Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Dynamic Dates between dax function

Hi Everyone,
 
Im trying to calculate the average values between two periods of dates. See below
 
CALCULATE(AVERAGE('Working Gas in Underground Storage (W)'[VALUE]),DATESBETWEEN('Working Gas in Underground Storage (W)'[DATE],date(2015,01,01),DATE(2019,12,31)))
 
However how can I make this dynamic?
 
I would like a 5 year rolling average but ignoring latest year. Currently 2020. ( We dont count it as we are currently in it) Any easy way to do this? As how I have it now i would have to come back and change the dates when 2021
 
Any help ideas are greatly appreciated it
 
 
3 ACCEPTED SOLUTIONS
edhans
Super User
Super User

Replace 2019 with YEAR(TODAY()) - 1

 

That will move forward. So DATE(YEAR(TODAY()) - 1, 12, 31)



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

You can update the formula of your measure or calculated column as below:

Measure =
CALCULATE (
    AVERAGE ( 'Working Gas in Underground Storage (W)'[VALUE] ),
    DATESBETWEEN (
        'Working Gas in Underground Storage (W)'[DATE],
        DATE ( Year(Today())-5, 01, 01 ),
        DATE ( Year(Today())-1, 12, 31 )
    )
)

Best Regards

Rena

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

amitchandak
Super User
Super User

@Anonymous , Check

last year end date = date(year(today())-1,12,31)
start date 5 years back = date(year(today())-5,1,1)

 

refer

https://community.powerbi.com/t5/Community-Blog/Date-as-Dateadd-Decoding-Date-and-Calendar-5-5-Power-BI-Turning/ba-p/1187827

 

 

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , Check

last year end date = date(year(today())-1,12,31)
start date 5 years back = date(year(today())-5,1,1)

 

refer

https://community.powerbi.com/t5/Community-Blog/Date-as-Dateadd-Decoding-Date-and-Calendar-5-5-Power-BI-Turning/ba-p/1187827

 

 

v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

You can update the formula of your measure or calculated column as below:

Measure =
CALCULATE (
    AVERAGE ( 'Working Gas in Underground Storage (W)'[VALUE] ),
    DATESBETWEEN (
        'Working Gas in Underground Storage (W)'[DATE],
        DATE ( Year(Today())-5, 01, 01 ),
        DATE ( Year(Today())-1, 12, 31 )
    )
)

Best Regards

Rena

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
edhans
Super User
Super User

Replace 2019 with YEAR(TODAY()) - 1

 

That will move forward. So DATE(YEAR(TODAY()) - 1, 12, 31)



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.