Forum Discussion
yuhkao
Microsoft Employee
6 years agoRolling 3 month
Hi I would like to have rolling data for calculation of [measure] for 3 months. please help me to create it. thanks date format is in YYYYMM format, which is text in data type now. for ...
MFelix
Super User
6 years agoHi yuhkao ,
Follow the steps below:
- Add a Endofmonth column in query editor or DAX:
Power Query:
Date.EndOfMonth(#date(
Number.FromText
(Text.Start(Number.ToText([Date]),4)),Number.FromText(Text.End(Number.ToText([Date]),2)),1))
DAX:
Month_End_DAX = EOMONTH(DATE(LEFT('Table'[Date];4);RIGHT('Table'[Date];2);1);0)
Now add the following measure to your model:
Rolling 3 month = CALCULATE(SUM('Table'[Data]);DATESINPERIOD('Table'[Month_End];MAX('Table'[Month_End]);-3;MONTH) ; ALLSELECTED('Table'[Data]))
Should return expected result.
yuhkao
Microsoft Employee
6 years ago- MFelix6 years ago
Super User
Hi yuhkao ,
This code is a calculated column in DAX in order to have a date column to use on the rolling 3 months.
Month_End_DAX = EOMONTH(DATE(LEFT('Table'[Date];4);RIGHT('Table'[Date];2);1);0)- yuhkao6 years ago
Microsoft Employee
Hi MFelix - as i used your method to generate rolling 3 month data. i place into table visual with time frame, why it only shows last 3 month rolling as total? for previous couples months, it only shows month data instead of rolling data.
- MFelix6 years ago
Super User
Hi yuhkao .
WIth the small amount of data you gave me it work correctly I did not had any issue. I just realize adding more data that I made an error on the filter the measure must be:
Rolling 3 month = CALCULATE(SUM('Table'[Data]);DATESINPERIOD('Table'[Month_End_DAX];MAX('Table'[Month_End_DAX]);-3;MONTH))Sorry for misleading you.