Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

DAX for Azure Cost Table - part 2

Hi everyone, I have a previous thread/message from the below link. https://community.powerbi.com/t5/Desktop/DAX-for-Azure-Cost-Table/m-p/1296381#M564798   Details are as follows: I have a tabl...
  • Anonymous's avatar
    Anonymous
    6 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.

    Unpivot columns (Power Query) 

    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

    Custom Sorting in Power BI 

    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