Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowGet inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.
I need help to add a new column to my table that will show the 6 month rolling average.
Date column to use is M-Y and want to get 6 month rolling average of the Order Value
Solved! Go to Solution.
Hi @bd27 ,
Sorry for being late!
You can try this DAX:
_average =
CALCULATE(
AVERAGE('Table'[Order Value]),
ALLEXCEPT('Table', 'Table'[Sold To Region]),
DATESINPERIOD(
'Table'[M-Y],
LASTDATE('Table'[M-Y]),
-6,
MONTH
)
)
And the final output is as below:
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @bd27 ,
Just as @lbendlin says, DAX will be much more easier.
Here is my sample data:
1. Power Query solution:
Just put all of these M funxtions into the Advanced Editor:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdJBDoQgDAXQu7DWRApUXKrHMN7/GkP/QIZ8MZkFZuIbfkvxupwsIrMXN7m9rKTl4d099XCUJWkAZ1kx9xDmxVdIan8REsvyaQBWPbwBivTw69d+BRIUWV5AUL6XUDtWHCqSoLERnG1eDEfr+O8dVkMCQaxR2JEILArtMqBdep/qe7V5KsHZboQBw1IC7c+3DgBRDHuLYrDieRSFT2u0Y8fBA8naBMPKneS+r43AqgQl2GrWFr+f0VMwx4fgdoeCW2xp9wc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"M-Y" = _t, #"Sold To Region" = _t, #"Order Value" = _t, #"Date Index" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"M-Y", type date}, {"Sold To Region", type text}, {"Order Value", Int64.Type}, {"Date Index", Int64.Type}}),
RollingAverage = Table.AddColumn(#"Changed Type", "Rolling Avg 6 Month", each List.Average(List.Transform(Table.SelectRows(#"Changed Type", (row) => row[#"M-Y"] <= [#"M-Y"] and row[#"M-Y"] > Date.AddMonths([#"M-Y"], -6))[Order Value], each _)))
in
RollingAverage
The final output is as below:
2. DAX solution:
Use this DAX to create a calculated column:
_average =
CALCULATE(
AVERAGE('Table'[Order Value]),
ALL('Table'),
DATESINPERIOD(
'Table'[M-Y],
LASTDATE('Table'[M-Y]),
-6,
MONTH
)
)
The final output is as below:
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi v-junyant-msft, thank you for your response. What do I need to add to DAX to separate it by Sold To Region? Region A should have a different value than B, etc.
Hi @bd27 ,
Sorry for being late!
You can try this DAX:
_average =
CALCULATE(
AVERAGE('Table'[Order Value]),
ALLEXCEPT('Table', 'Table'[Sold To Region]),
DATESINPERIOD(
'Table'[M-Y],
LASTDATE('Table'[M-Y]),
-6,
MONTH
)
)
And the final output is as below:
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Does it have to be Power Query ? This would be much easier using the DAX WINDOW function.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
31 | |
31 | |
22 | |
16 | |
12 |
User | Count |
---|---|
21 | |
20 | |
16 | |
11 | |
10 |