Forum Discussion
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 matrixRows = Name
Columns = Headers[Header]
Values = [Value]
5 Replies
- rohit1991
Super User
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.
- Tahreem24
Super User
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 matrixRows = Name
Columns = Headers[Header]
Values = [Value] - ryan_mayu
Super User
could you pls provide some sample data? how many tables do you have ?
- Ashish_Mathur
Super User
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.
- v-sathmakuri
Community Support
Hi lherbert501 ,
Thank you for reaching out to fabric community.
I have attached the pbix file with the required output. could you please check from your end.
Thanks!!