Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Matrix : Double headers in matrix visual

How can i achieve below kind of view in power bi matrix visual?

Thanks in Advance

  • Hi Anonymous ,

     

    Please create the new table.

     

    Columns = 
    UNION (
        CROSSJOIN ( { "By Product" }, VALUES ( 'Table'[Product] ) ),
        CROSSJOIN ( { "By Year" }, VALUES ( 'Table'[Year] ) ),
        CROSSJOIN (
            { "Summarizations" },
            SELECTCOLUMNS (
                { "Total", "% of Total Sales", "Avg Sale Size" },
                "value2", [Value]
            )
        )
    )

     

    Then create the measure.

     

    MatrixValue = 
    VAR ByProduct =
        CALCULATE (
            SUM ( 'Table'[Sales] ),
            FILTER ( 'Table', 'Table'[Product] = MAX ( 'Columns'[Sub_header] ) )
        )
    VAR ByYear =
        CALCULATE (
            SUM ( 'Table'[Sales] ),
            FILTER (
                'Table',
                FORMAT ( 'Table'[Year], 0000 ) = MAX ( 'Columns'[Sub_header] )
            )
        )
    VAR total = SUM ( 'Table'[Sales] )
    VAR totalPercent = total / SUMX ( ALL ( 'Table' ), 'Table'[Sales] )
    VAR Avg_ = AVERAGE ( 'Table'[Sales] )
    RETURN
        SWITCH (
            MAX ( 'Columns'[Header] ),
            "By Product", ByProduct,
            "By Year", ByYear,
            SWITCH (
                MAX ( 'Columns'[Sub_header] ),
                "Total", total,
                "% of Total Sales", FORMAT ( totalPercent, "Percent" ),
                "Avg Sale Size", FORMAT ( Avg_, ".0" )
            )
        )

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
    Best Regards,
    Winniz
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

1 Reply

  • v-kkf-msft's avatar
    v-kkf-msft
    Community Support

    Hi Anonymous ,

     

    Please create the new table.

     

    Columns = 
    UNION (
        CROSSJOIN ( { "By Product" }, VALUES ( 'Table'[Product] ) ),
        CROSSJOIN ( { "By Year" }, VALUES ( 'Table'[Year] ) ),
        CROSSJOIN (
            { "Summarizations" },
            SELECTCOLUMNS (
                { "Total", "% of Total Sales", "Avg Sale Size" },
                "value2", [Value]
            )
        )
    )

     

    Then create the measure.

     

    MatrixValue = 
    VAR ByProduct =
        CALCULATE (
            SUM ( 'Table'[Sales] ),
            FILTER ( 'Table', 'Table'[Product] = MAX ( 'Columns'[Sub_header] ) )
        )
    VAR ByYear =
        CALCULATE (
            SUM ( 'Table'[Sales] ),
            FILTER (
                'Table',
                FORMAT ( 'Table'[Year], 0000 ) = MAX ( 'Columns'[Sub_header] )
            )
        )
    VAR total = SUM ( 'Table'[Sales] )
    VAR totalPercent = total / SUMX ( ALL ( 'Table' ), 'Table'[Sales] )
    VAR Avg_ = AVERAGE ( 'Table'[Sales] )
    RETURN
        SWITCH (
            MAX ( 'Columns'[Header] ),
            "By Product", ByProduct,
            "By Year", ByYear,
            SWITCH (
                MAX ( 'Columns'[Sub_header] ),
                "Total", total,
                "% of Total Sales", FORMAT ( totalPercent, "Percent" ),
                "Avg Sale Size", FORMAT ( Avg_, ".0" )
            )
        )

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
    Best Regards,
    Winniz
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.