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.
Hi
I need to calculate a rolling 3 months average of a measure.
In my table, I have a Date column, but the monthly measurement period is not from 01-30/31 (like Jan is from 01.Jan-31.Jan), but from 15 previous month -14 current month (like Jan is 15.Dec - 14.Jan) .
I create a new column to identify the measurement period.
Solved! Go to Solution.
Hi @e2liu77 ,
Please check the following steps as below.
1. Create a date table and create relationship between the fact table and it.
Table = CALENDAR(DATE(2017,01,01),DATE(2019,12,31))
2. Create two calculated column in your fact table as below.
YearMonth = var _date = DATEADD('Table'[Date],1,MONTH) return YEAR(_date)*100+MONTH(_date)
Year Month 2 = var _date= DATEADD('Table'[Date],-1,MONTH) return YEAR(_date)*100+MONTH(_date)
3. Then we can create a measure to achieve your goal.
average 3 = SUMX ( FILTER ( ALL ( DataSource[YearMonth] ), DataSource[YearMonth] <= MAX ( DataSource[YearMonth] ) && 'DataSource'[YearMonth] >= MAX ( DataSource[Year Month 2] ) ), [Test Scorecard] ) / CALCULATE ( DISTINCTCOUNT ( DataSource[YearMonth] ), FILTER ( ALL ( DataSource[YearMonth] ), DataSource[YearMonth] <= MAX ( DataSource[YearMonth] ) && 'DataSource'[YearMonth] >= MAX ( DataSource[Year Month 2] ) ) )
Pbix as attached.
Regards,
Frank
Hi @e2liu77 ,
We can create a measure as below.
Measure = SUMX ( FILTER ( ALL ( Table1 ), Table1[Column] <= MAX ( Table1[Column] ) ), [Testing Scorecard1] ) / CALCULATE ( COUNTROWS ( Table1 ), FILTER ( ALL ( Table1 ), Table1[Column] <= MAX ( Table1[Column] ) ) )
Pbix as attached.
Regards,
Frank
Hi Frank,
Thanks for helping me.
I checked your PBIX file and found that your [Test scorecard] is a column, but mine is a measure. With your measure DAX formula it will not work.
I attached my PBIX for your reference. Any idea how to change my formula?
Hi @e2liu77 ,
Please check the following steps as below.
1. Create a date table and create relationship between the fact table and it.
Table = CALENDAR(DATE(2017,01,01),DATE(2019,12,31))
2. Create two calculated column in your fact table as below.
YearMonth = var _date = DATEADD('Table'[Date],1,MONTH) return YEAR(_date)*100+MONTH(_date)
Year Month 2 = var _date= DATEADD('Table'[Date],-1,MONTH) return YEAR(_date)*100+MONTH(_date)
3. Then we can create a measure to achieve your goal.
average 3 = SUMX ( FILTER ( ALL ( DataSource[YearMonth] ), DataSource[YearMonth] <= MAX ( DataSource[YearMonth] ) && 'DataSource'[YearMonth] >= MAX ( DataSource[Year Month 2] ) ), [Test Scorecard] ) / CALCULATE ( DISTINCTCOUNT ( DataSource[YearMonth] ), FILTER ( ALL ( DataSource[YearMonth] ), DataSource[YearMonth] <= MAX ( DataSource[YearMonth] ) && 'DataSource'[YearMonth] >= MAX ( DataSource[Year Month 2] ) ) )
Pbix as attached.
Regards,
Frank
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
115 | |
100 | |
88 | |
70 | |
61 |
User | Count |
---|---|
151 | |
120 | |
103 | |
87 | |
68 |