Forum Discussion
DAX for Azure Cost Table - part 2
- Anonymous6 years ago
Hi Anonymous,
I'd like to suggest you do unpivot columns on your month fields to convert them to attribute and value fields to calculate.
Then you can create a sorting table to setting custom sort order of month fields and duplicate it as a selector table to use on the slicer. (sort table link to raw table month fields, selector table not has any relationship to other tables)
Sorting = SELECTCOLUMNS ( GENERATESERIES ( 1, 12, 1 ), "Index", [Value], "Month", FORMAT ( DATEVALUE ( [Value] & "/1" ), "mmm" ) ) Selector = SortingAfter these steps, you can design matrix visual with raw table resource Group, sort order table month, and write a measure to interact with slicer and calculated the selected diff. (name column subtotal as diff)
result = VAR selected = CALCULATE ( MAX ( 'Selector'[Index] ), ALLSELECTED ( 'Selector' ) ) VAR list = CALCULATETABLE ( VALUES ( Sorting[Month] ), FILTER ( ALL ( Sorting ), [Index] IN { selected - 1, selected } ) ) RETURN IF ( ISINSCOPE ( Sorting[Month] ), IF ( SELECTEDVALUE ( Sorting[Month] ) IN list, SUM ( Test[Sales] ) ), CALCULATE ( CALCULATE ( SUM ( Test[Sales] ), Sorting[Index] = selected - 1 ) - CALCULATE ( SUM ( Test[Sales] ), Sorting[Index] = selected ), ALLSELECTED ( Test ), VALUES ( Test[resourceGroup] ) ) )BTW, I also attached the sample pbix file below, you can check it if you still confused about how to do these.
Regards,
Xiaoxin Sheng
Hi Anonymous,
I'd like to suggest you do unpivot columns on your month fields to convert them to attribute and value fields to calculate.
Then you can create a sorting table to setting custom sort order of month fields and duplicate it as a selector table to use on the slicer. (sort table link to raw table month fields, selector table not has any relationship to other tables)
Sorting =
SELECTCOLUMNS (
GENERATESERIES ( 1, 12, 1 ),
"Index", [Value],
"Month", FORMAT ( DATEVALUE ( [Value] & "/1" ), "mmm" )
)
Selector = Sorting
After these steps, you can design matrix visual with raw table resource Group, sort order table month, and write a measure to interact with slicer and calculated the selected diff. (name column subtotal as diff)
result =
VAR selected =
CALCULATE ( MAX ( 'Selector'[Index] ), ALLSELECTED ( 'Selector' ) )
VAR list =
CALCULATETABLE (
VALUES ( Sorting[Month] ),
FILTER ( ALL ( Sorting ), [Index] IN { selected - 1, selected } )
)
RETURN
IF (
ISINSCOPE ( Sorting[Month] ),
IF ( SELECTEDVALUE ( Sorting[Month] ) IN list, SUM ( Test[Sales] ) ),
CALCULATE (
CALCULATE ( SUM ( Test[Sales] ), Sorting[Index] = selected - 1 )
- CALCULATE ( SUM ( Test[Sales] ), Sorting[Index] = selected ),
ALLSELECTED ( Test ),
VALUES ( Test[resourceGroup] )
)
)
BTW, I also attached the sample pbix file below, you can check it if you still confused about how to do these.
Regards,
Xiaoxin Sheng