Forum Discussion

lherbert501's avatar
lherbert501
Icon for Post Prodigy rankPost Prodigy
2 months ago
Solved

Matrix column not grouped

Hi,

 

Is it possible to obtain this outcome below using a matrix? 

 

The remaining part needs to be out of the scope of the months, but it also has to be calculated on the fly.

 

Thanks

 

 

  • Hii lherbert501 

     

    You need a disconnected column-layout table because a standard matrix cannot mix standalone measures with month-grouped columns directly. Add Section and Column to the matrix Columns, then use one measure:

    Matrix Value =
    VAR Header  = SELECTEDVALUE ( 'Matrix Columns'[Column] )
    VAR MonthNo = SELECTEDVALUE ( 'Matrix Columns'[MonthNo] )
    RETURN
    SWITCH (
        TRUE(),
        Header = "Allowed", [Allowed],
        Header = "Remaining", [Allowed] - [Total Spend],
        CALCULATE (
            [Spend],
            TREATAS ( { MonthNo }, 'Calendar'[MonthNo] )
        )
    )

    Set Section to blank for Allowed/Remaining and Spend for the month columns, apply sort columns, and disable column subtotals. For multiple years, use a Year-Month key instead of Month Number.

  • lherbert501 ,
    Step 1: Create a disconnected table (Enter Data), Headers:

     

    Set Sort as the Sort-By column for Header. Don't relate this table to anything.

    Step 2: Create  a measure:
    Value =
    VAR h = SELECTEDVALUE ( Headers[Header] )
    VAR AllowedVal = SUM ( Allowed[Amount] )
    VAR TotalSpend = CALCULATE ( SUM ( Spend[Amount] ) ) -- all months, ignores Headers
    RETURN
    SWITCH (
    h,
    "allowed", AllowedVal,
    "remaining", AllowedVal - TotalSpend,
    // month columns:
    CALCULATE ( SUM ( Spend[Amount] ), Spend[MonthName] = h )
    )

    Step 3: Build the matrix

    Rows = Name
    Columns = Headers[Header]
    Values = [Value]

     

     

5 Replies

  • Hii lherbert501 

     

    You need a disconnected column-layout table because a standard matrix cannot mix standalone measures with month-grouped columns directly. Add Section and Column to the matrix Columns, then use one measure:

    Matrix Value =
    VAR Header  = SELECTEDVALUE ( 'Matrix Columns'[Column] )
    VAR MonthNo = SELECTEDVALUE ( 'Matrix Columns'[MonthNo] )
    RETURN
    SWITCH (
        TRUE(),
        Header = "Allowed", [Allowed],
        Header = "Remaining", [Allowed] - [Total Spend],
        CALCULATE (
            [Spend],
            TREATAS ( { MonthNo }, 'Calendar'[MonthNo] )
        )
    )

    Set Section to blank for Allowed/Remaining and Spend for the month columns, apply sort columns, and disable column subtotals. For multiple years, use a Year-Month key instead of Month Number.

  • lherbert501 ,
    Step 1: Create a disconnected table (Enter Data), Headers:

     

    Set Sort as the Sort-By column for Header. Don't relate this table to anything.

    Step 2: Create  a measure:
    Value =
    VAR h = SELECTEDVALUE ( Headers[Header] )
    VAR AllowedVal = SUM ( Allowed[Amount] )
    VAR TotalSpend = CALCULATE ( SUM ( Spend[Amount] ) ) -- all months, ignores Headers
    RETURN
    SWITCH (
    h,
    "allowed", AllowedVal,
    "remaining", AllowedVal - TotalSpend,
    // month columns:
    CALCULATE ( SUM ( Spend[Amount] ), Spend[MonthName] = h )
    )

    Step 3: Build the matrix

    Rows = Name
    Columns = Headers[Header]
    Values = [Value]

     

     

  • could you pls provide some sample data? how many tables do you have ?

  • Hi,

    If you are OK with allowed and remaining being the last 2 columns, then i can try.  Please share the download link of the PBI file.