Forum Discussion

veerach's avatar
veerach
Frequent Visitor
4 years ago
Solved

Matrix visual - Regular and Dynamic columns - is this possible?

Hi everyone, 

I have data like this

AreaCompanyProductOrdered QtyActual Qty
AMatrix IncPen4411
AMatrix IncPaper5025
AMatrix IncBook107
AMatrix IncStand1612
ATech CoPen2016
ATech CoPaper3515
BApptechBook155
BApptechStand2510
BApptechBench107
BApptechPen1612
BZ IncPaper2016
BZ IncBook3515
BZ IncCard5025

 

I have a requirement to show the data in this format

       
AreaCompany CountTotal OrderedTotal Actual% Actual/OrderedOrdered PenPaperBookStandBenchCardActual PenPaperBookStandBenchCard
A21758649%66851016  2741712  
B21719053%16205025105012162010725

 

The products are dynamic in nature, I tried to use Matrix visual. Either I can do count, totals and percentage or only products. Can anyone suggest an approach to include both in same visual. (The idea here is user wants to see aggregate values by area, if he wants he can drill down to company level to see the details.)

 

Thanks

Veera

 

  • Hi veerach ,

     

    1. Please unpivot the Ordered Qty and the Actual Qty columns.

     

    2. Create the new table: MatrixTable.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WUtJRcs7PLUjMq1Rwzi/NK1GK1QELhuSXJOYo+BelpBalpqAKOiaXlCbmwMRUoXx9uNpYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, Product = _t]),
        #"Appended Query" = Table.Combine({Source,Table.SelectColumns(Table,{"Category","Product"})}),
        #"Removed Duplicates" = Table.Distinct(#"Appended Query")
    in
        #"Removed Duplicates"

     

    3. Create the table: SlicerTable.

     

    let
        Source = Table.SelectColumns(Table,"Product"),
        #"Removed Duplicates" = Table.Distinct(Source),
        #"Added Custom" = Table.AddColumn(#"Removed Duplicates", "MatrixColumns", each Table.Distinct( Table.SelectColumns(MatrixTable,"Product") )),
        #"Expanded MatrixColumns" = Table.ExpandTableColumn(#"Added Custom", "MatrixColumns", {"Product"}, {"MatrixColumns"}),
        #"Filtered Rows" = Table.SelectRows(#"Expanded MatrixColumns", each ([MatrixColumns] = "% Actual/Ordered" or [MatrixColumns] = "Company Count" or [MatrixColumns] = "Total Actual" or [MatrixColumns] = "Total Ordered" or [MatrixColumns] = [Product]))
    in
        #"Filtered Rows"

     

    4. Create the relationship.

     

     

    5. Create the measure.

     

    Measure = 
    VAR filtertab =
        TREATAS ( VALUES ( MatrixTable[Product] ), 'Table'[Product] )
    RETURN
        SWITCH (
            MAX ( MatrixTable[Category] ),
            "Ordered Qty", CALCULATE ( [Total Ordered], filtertab ),
            "Actual Qty", CALCULATE ( [Total Actual], filtertab ),
            SWITCH (
                MAX ( MatrixTable[Product] ),
                "Company Count", [Company Count],
                "Total Ordered", [Total Ordered],
                "Total Actual", [Total Actual],
                "% Actual/Ordered", FORMAT ( [% Actual/Ordered], "Percent" )
            )
        )

     

    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
    Icon for Community Support rankCommunity Support

    Hi veerach ,

     

    1. Please unpivot the Ordered Qty and the Actual Qty columns.

     

    2. Create the new table: MatrixTable.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WUtJRcs7PLUjMq1Rwzi/NK1GK1QELhuSXJOYo+BelpBalpqAKOiaXlCbmwMRUoXx9uNpYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, Product = _t]),
        #"Appended Query" = Table.Combine({Source,Table.SelectColumns(Table,{"Category","Product"})}),
        #"Removed Duplicates" = Table.Distinct(#"Appended Query")
    in
        #"Removed Duplicates"

     

    3. Create the table: SlicerTable.

     

    let
        Source = Table.SelectColumns(Table,"Product"),
        #"Removed Duplicates" = Table.Distinct(Source),
        #"Added Custom" = Table.AddColumn(#"Removed Duplicates", "MatrixColumns", each Table.Distinct( Table.SelectColumns(MatrixTable,"Product") )),
        #"Expanded MatrixColumns" = Table.ExpandTableColumn(#"Added Custom", "MatrixColumns", {"Product"}, {"MatrixColumns"}),
        #"Filtered Rows" = Table.SelectRows(#"Expanded MatrixColumns", each ([MatrixColumns] = "% Actual/Ordered" or [MatrixColumns] = "Company Count" or [MatrixColumns] = "Total Actual" or [MatrixColumns] = "Total Ordered" or [MatrixColumns] = [Product]))
    in
        #"Filtered Rows"

     

    4. Create the relationship.

     

     

    5. Create the measure.

     

    Measure = 
    VAR filtertab =
        TREATAS ( VALUES ( MatrixTable[Product] ), 'Table'[Product] )
    RETURN
        SWITCH (
            MAX ( MatrixTable[Category] ),
            "Ordered Qty", CALCULATE ( [Total Ordered], filtertab ),
            "Actual Qty", CALCULATE ( [Total Actual], filtertab ),
            SWITCH (
                MAX ( MatrixTable[Product] ),
                "Company Count", [Company Count],
                "Total Ordered", [Total Ordered],
                "Total Actual", [Total Actual],
                "% Actual/Ordered", FORMAT ( [% Actual/Ordered], "Percent" )
            )
        )

     

    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.