Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Matrix visual with difference calculation from total row

I need to create a matrix visual that looks like the following: Train Day 6 Day 7 Day 8 Loc. A 2088 2204 2088 Loc. B 1508 1508 2436 Total 3596 3712 4524 Capacity 4000 ...
  • v-kkf-msft's avatar
    4 years ago

    Hi Anonymous ,

     

    Please create a new table.

     

    Table = 
    VAR newcapacity =
        CROSSJOIN ( Capacity, VALUES ( Train[Day] ) )
    VAR UnionTab =
        UNION (
            Train,
            SELECTCOLUMNS (
                newcapacity,
                "Company", [Company],
                "Train", "Capacity",
                "Day", [Day],
                "Load", [Capacity]
            )
        )
    RETURN
        ADDCOLUMNS (
            UnionTab,
            "Type", IF ( [Train] = "Capacity", "Capacity", "Train" )
        )

     

    Then create these measures.

     

    Load and Capacity = 
    CALCULATE ( SUM ( 'Table'[Load] ), 'Table'[Company] = "Company A" )
    TotalValue = 
    VAR diff =
        CALCULATE ( [Load and Capacity], 'Table'[Type] = "Train" )
            - CALCULATE ( [Load and Capacity], 'Table'[Type] = "Capacity" )
    RETURN
        IF ( ISFILTERED ( 'Table'[Type] ), [Load and Capacity], diff )

     

    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.