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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Astro1990
Frequent Visitor

Start calculation from last year of max date (Running Average)


Hi everyone.

I am struggling abit with this running average.

Measure =
CALCULATE(
DIVIDE((SUM('Sheet1'[Aqua])*358),(sum('sheet1'[Wlk3]))),
FILTER(
ALLSELECTED('Sheet1'[Date]),
ISONORAFTER('Sheet1'[Date], MAX('Sheet1'[Date]), DESC)
)
)

It works really good, but I only want the calculation starting last year from MAX.

Since I have data from 3-4 years ago, which would not be relevant for me.

Is there a way to start the calculation from exactly 1 year ago?

Thank you so much in advance! 😀

Let me know if there is any other data I should show.

1 ACCEPTED SOLUTION

Hi @Astro1990 ,

 

As far as I know, DATESINPERIOD() will work if you have continuous date in your data model. So if there is continuous date in Sheet1, you will get correct result. You can add a dimdate table by CALENDAR() or CALENDARAUTO() with continuous date as well.

I think you can achieve your goal with Filter() function as well. Try this code.

Measure = 
VAR _LASTDATE = MAXX(ALL(Sheet1),Sheet1[Date])
RETURN
CALCULATE(
DIVIDE((SUM('Sheet1'[Aqua])*358),(sum('sheet1'[Wlk3]))),
FILTER(
Sheet1,
Sheet1[Date] > EOMONTH(_LASTDATE,-12)
)
)

 

 

Best Regards,
Rico Zhou

 

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

3 REPLIES 3
Astro1990
Frequent Visitor

Thank you so much Rico!

It worked wonderfully!

Astro1990
Frequent Visitor

I think I corrected it. Instead of Filter, I used DatesinPeriod.
It looks great! Still checking if it, so I'll post here once I finished checking. 

FILTER(
ALLSELECTED('Sheet1'[Date]),
ISONORAFTER('Sheet1'[Date], MAX('Sheet1'[Date]), DESC)
)
)

To the following:

    DATESINPERIOD(
    DATESINPERIOD(
'Sheet1'[Date],
LASTDATE('Sheet1'[Date]),
-12,
MONTH
    )
)

Hi @Astro1990 ,

 

As far as I know, DATESINPERIOD() will work if you have continuous date in your data model. So if there is continuous date in Sheet1, you will get correct result. You can add a dimdate table by CALENDAR() or CALENDARAUTO() with continuous date as well.

I think you can achieve your goal with Filter() function as well. Try this code.

Measure = 
VAR _LASTDATE = MAXX(ALL(Sheet1),Sheet1[Date])
RETURN
CALCULATE(
DIVIDE((SUM('Sheet1'[Aqua])*358),(sum('sheet1'[Wlk3]))),
FILTER(
Sheet1,
Sheet1[Date] > EOMONTH(_LASTDATE,-12)
)
)

 

 

Best Regards,
Rico Zhou

 

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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