Forum Discussion
Gazsim44
Helper III
6 years agoYTD Average & Average Change
Hi All, I have a matrix setup where I need to add additional columns to indicate the changes in prior month figures, YTD average and also the change if possible of that average from one month t...
- 6 years ago
Hi,
According to your description, i create a sample to test:
Please try to create a column header first:
ColumnHeader = UNION ( ADDCOLUMNS ( DISTINCT ( 'Table'[Date].[MonthNo] ), "Month", FORMAT ( DATE ( 2020, [Date].[MonthNo], 1 ), "MMM" ) ), DATATABLE ( "MonthNo", INTEGER, "Month", STRING, { { 13, "Change from Prior Month" } } ), DATATABLE ( "MonthNo", INTEGER, "Month", STRING, { { 14, "YTD Average" } } ), DATATABLE ( "MonthNo", INTEGER, "Month", STRING, { { 15, "Change from Prior Average" } } ) )It shows:
Then create a measure:
Measure = VAR MaxMonth = MONTH ( MAX ( 'Table'[Date] ) ) VAR LastMonth = MONTH ( MAX ( 'Table'[Date] ) ) - 1 RETURN SWITCH ( MAX ( ColumnHeader[Month] ), "Jan", CALCULATE ( SUM ( 'Table'[Values] ), FILTER ( 'Table', MONTH ( 'Table'[Date] ) = 1 ) ), "Feb", CALCULATE ( SUM ( 'Table'[Values] ), FILTER ( 'Table', MONTH ( 'Table'[Date] ) = 2 ) ), "Mar", CALCULATE ( SUM ( 'Table'[Values] ), FILTER ( 'Table', MONTH ( 'Table'[Date] ) = 3 ) ), "Change from Prior Month", CALCULATE ( SUM ( 'Table'[Values] ), FILTER ( 'Table', MONTH ( 'Table'[Date] ) = MaxMonth ) ) - CALCULATE ( SUM ( 'Table'[Values] ), FILTER ( 'Table', MONTH ( 'Table'[Date] ) = LastMonth ) ), "YTD Average", FIXED ( AVERAGE ( 'Table'[Values] ), 2 ), "Change from Prior Average", FIXED ( AVERAGE ( 'Table'[Values] ) - CALCULATE ( AVERAGE ( 'Table'[Values] ), FILTER ( 'Table', MONTH ( 'Table'[Date] ) <> MaxMonth ) ), 2 ) )Apply a filter to matrix visual such as [Category]="AAA", the result shows:
Here is my test pbix file:
Hope this helps.
Best Regards,
Giotto Zhi
Gazsim44
Helper III
6 years agoMany thanks Giotto - that works fantastic! 🙂
My only further question is I am using whole number values only however although I have changed the format to this for the measure the YTD Average & Change from Prior Average columns still appear as decimals? Any ideas why this is?
Thanks again,
v-gizhi-msft
Community Support
6 years agoHi,
It is because after calculated by AVERAGE, the result will appear as decimals type.
It is by design.
Best Regards,
Giotto Zhi