Forum Discussion
Adding a previous and current 12 month column
Hi s2anya,
If I understand you correctly, I don't think there is an easy way to do it in Power BI currently. You may need to firstly create 12 measures to extract the 12 months' data separately.
Month 1 =
VAR maxYM =
CALCULATE ( MAX ( Table1[YearMonth] ), ALL ( Table1 ) )
RETURN
CALCULATE (
SUM ( Table1[KPI] ),
FILTER ( ALLEXCEPT ( Table1, Table1[State] ), Table1[YearMonth] = maxYM )
)
Month 2 =
VAR maxYM =
CALCULATE ( MAX ( Table1[YearMonth] ), ALL ( Table1 ) )
RETURN
CALCULATE (
SUM ( Table1[KPI] ),
FILTER ( ALLEXCEPT ( Table1, Table1[State] ), Table1[YearMonth] = maxYM - 1 )
)
.
.
.
Month 12 =
VAR maxYM =
CALCULATE ( MAX ( Table1[YearMonth] ), ALL ( Table1 ) )
RETURN
CALCULATE (
SUM ( Table1[KPI] ),
FILTER ( ALLEXCEPT ( Table1, Table1[State] ), Table1[YearMonth] = maxYM - 11 )
)
And create another 3 measures to calculate previous and current 12 month's KPI and their changes.
Current 12 months =
VAR maxYM =
CALCULATE ( MAX ( Table1[YearMonth] ), ALL ( Table1 ) )
RETURN
CALCULATE (
SUM ( Table1[KPI] ),
FILTER (
ALLEXCEPT ( Table1, Table1[State] ),
Table1[YearMonth]
> maxYM - 12
&& Table1[YearMonth] <= maxYM
)
)
Previous 12 months =
VAR maxYM =
CALCULATE ( MAX ( Table1[YearMonth] ), ALL ( Table1 ) )
RETURN
CALCULATE (
SUM ( Table1[KPI] ),
FILTER (
ALLEXCEPT ( Table1, Table1[State] ),
Table1[YearMonth]
> maxYM - 24
&& Table1[YearMonth]
<= maxYM - 12
)
)
Change % = DIVIDE([Current 12 months]-[Previous 12 months],[Previous 12 months])
Then you should be able to show State column as Rows, and all the 15 measures as Values on the Matrix visual to get the expected result in your scenario. :smileyhappy:
Regards
Hi v-ljerr-msft,
Thanks for a quick response.
One question here, What about the column names? Cannot leave it as month1, month2 etc. It should be a date.
Regards
- v-ljerr-msft8 years agoMicrosoft Employee
Hi s2anya,
One question here, What about the column names? Cannot leave it as month1, month2 etc. It should be a date.
I understand that. But I don't think there is a way show the date as name for these measures directly. You may need to change the measure name manually. :smileyhappy:
Regards