Forum Discussion

DebbieE's avatar
DebbieE
Icon for Community Champion rankCommunity Champion
7 years ago
Solved

Matrix, Mixing Columns (For example Months, then Quarters as columns)

I have a report that a customer wants me to recreate   But it turns out to be really difficult to do   Filter 2019                 Jan    Feb    Mar   Apr   May   Jun     Jul   Aug    Sep    Oct...
  • Anonymous's avatar
    Anonymous
    7 years ago

    Hi DebbieE ,

    You can create a custom sort table with all month and quarters and setting 'sort by column' feature on these fields.

    Sort table = 
    SELECTCOLUMNS (
        GENERATESERIES ( 1, 16, 1 ),
        "Index", [Value],
        "Desc", IF (
            [Value] <= 12,
            FORMAT ( DATEVALUE ( [Value] & "/1/2019" ), "mmm" ),
            "Q" & [Value] - 12
        )
    )

    After these steps, you can use original matrix row with new table fields to create a matrix. For value fields, you can write a measure to calculate correspond result based on current category and column label.

    Measure =
    VAR currLable =
        MAX ( 'Sort Table'[Desc] )
    RETURN
        IF (
            currLable IN { "Q1", "Q2", "Q3", "Q4" },
            CALCULATE (
                SUM ( table[Amount] ),
                FILTER (
                    ALLSELECTED ( Table ),
                    MONTH ( [Date] )
                        >= RIGHT ( currLable, 1 ) * 3 - 2
                        && MONTH ( [Date] )
                            <= RIGHT ( currLable, 1 ) * 3
                ),
                VALUES ( Table[Group] )
            ),
            CALCULATE (
                SUM ( table[Amount] ),
                FILTER ( ALLSELECTED ( Table ), FORMAT ( [Date], "mmm" ) = currLable ),
                VALUES ( Table[Group] )
            )
        )
    

    Regards,

    Xiaoxin Sheng