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
Gladiator909
Helper I
Helper I

Average of Past Months for future Value

Hi there,

 

I have the following table:

DateValue
2022/Jan
1
2022/Feb2
2022/Mar3
2022/Apr5
2022/May2
2022/Jun6
2022/Jul1
2022/Aug23
2022/Sep5
2022/Oct6
2022/Nov8
2022/Dec2
2023/Jan3
2023/Feb5
2023/Mar1

 

I now want to predict the value for the months coming affter March. That is predict the value for april, may, june to december. And I need to do this using the average of the previous months.

 

So in Excel, if I want to find 2023/Apr = Average(B15:B17)

Gladiator909_0-1680711840442.png

 

Now for the subsequent months, I just drag the edge of the box all the way down and it does the average for me.

 

So average for 2023/May = AVERAGE(B16:B18) (Note: it includes B18 that was previously calculated)

 

I am trying to find a way to do that in DAX or Power Query inside Power BI but I can't seem to find a way.

 

Any ideas?

 

Thanks

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

Hard to implement logic of such recursive calculation by DAX; but lightweight for PQ.

 

let
    n = 9,
    Source = {3,5,1},
    #"Rolling Avg" = List.Accumulate({4..n+3}, Source, (s,c) => s & {List.Average(List.LastN(s, 3))}),
    ToTable = Table.FromColumns({List.Transform({1..n+3}, each Date.ToText(Date.AddMonths(#date(2023,1,1),_-1), "yyyy MMM")), #"Rolling Avg"}, {"Yr Mth", "Value"})
in
    ToTable

 

CNENFRNL_0-1680719389409.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

Hard to implement logic of such recursive calculation by DAX; but lightweight for PQ.

 

let
    n = 9,
    Source = {3,5,1},
    #"Rolling Avg" = List.Accumulate({4..n+3}, Source, (s,c) => s & {List.Average(List.LastN(s, 3))}),
    ToTable = Table.FromColumns({List.Transform({1..n+3}, each Date.ToText(Date.AddMonths(#date(2023,1,1),_-1), "yyyy MMM")), #"Rolling Avg"}, {"Yr Mth", "Value"})
in
    ToTable

 

CNENFRNL_0-1680719389409.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Jihwan_Kim
Super User
Super User

Hi,

One of ways to achieve this is,

1. create a function in Power Query Editor like below.

Jihwan_Kim_0-1680718013875.png

 

2. and then follow the advanced editor like below.

Jihwan_Kim_1-1680718071920.png

 

Please check the attached pbix file.

Thank you.

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


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.