Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedJoin us at the 2025 Microsoft Fabric Community Conference. March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for $400 discount. Register now
Scenario:
Although there is no direct operation to put the total row in front of the matrix column in Power bi, we can still make it by using below two methods.
1. Use the summarized function to form a new table of data string “Total”, and add a space string at the top of it, then add the new table to the original one through the union function, and finally, “Total with spaces” will go to the top automatically when they match alphabetically.
2. Create a special column that contains “Total” and " Total" contains empty characters. According to the alphabetical order, it will be the first column in the matrix. Create a measure to determine whether the selected is " Total", Yes, SUM is performed, if not, the current value is assigned.
Sample Data:
‘Row Table’: Here's the sample table that contains the data between 2020 / 1 / 1 and 2020 / 1 / 3 to calculate the row subtotal.
‘Column Table’: Here's the sample table that contains the data between 2020 / 1 / 1 and 2020 / 1 / 3 to calculate the column subtotal.
Expected output:
‘Row Table’:
‘Column Table’:
Guideline:
There are two methods:
Column Subtotal:
Column Subtotal:
2. Put the data in the table into the matrix in this form (Row= 'Column Table'[Name], Column= ‘Date select’[Date], Values= ‘Column Table’[Value]), then you will see “Total” in the matrix, since the string with a space is sorted alphabetically, it will be sorted to the left automatically. Then we create a measure to determine whether the selection is " Total", Yes, SUM will be performed, if not, the current value will be assigned.
Operations:
Row Subtotal:
‘Row SubTotal’ =
VAR _summarize =
SUMMARIZE (
'‘Row Table’',
[Date],
"Name", " Total",
"Value", SUM ( ’Row Table’[Value] )
)
RETURN
UNION ( '‘Row Table’', _summarize )
Note:
The space character in " Total" will automatically rank Total according to the alphabetical order to the leftmost side of the matrix to prevent confusion due to the alphabetical order.
Result:
Step analysis:
Use the summarize function to create a calculated table with the Date column as the group, the Name column as the “Total”, and the Value column data as the added calculated column table after grouping, and then use the union function to append the calculated table and ‘Row Table’.
Result:
Step analysis:
The Name column of the new formed table “Row Sub Total” is composed of ABC type data and " Total". After placing it in the matrix, " Total" will be placed on the leftmost side according to the alphabetical order due to the space string.
Column Subtotal
‘Column Sub Total’ =
VAR _summarize =
SUMMARIZE (
'‘Column Table’',
[Name],
"Date", " Total",
"Value", SUM ( ’Column Table’[Value] )
)
RETURN
UNION ( '‘Column Table’', _summarize )
Result:
Step analysis:
Use the summarize function to create a calculated table with the Name column as the grouping and the Date column as " Total", and the Value column data as the added calculated column table after grouping, and then use the union function to append the calculated table and ‘Column Table’.
Result:
Step analysis:
The Date column of the new table ‘Column Sub Total’ formed is composed of 2020/1/1 date type data and " Total". After placing it in the matrix, " Total" will be placed on the leftmost side according to the alphabetical order due to the space string.
Row Subtotal:
‘Name select’ =
UNION (
DISTINCT ( ’Row Table’[Name] ),
DATATABLE ( "Name", STRING, { { " Total" } } )
)
Result:
Step analysis:
Use distinct to de-duplicate the name in the table ‘Row Table’, use datatable() to create data containing " Total" in the Name column, and perform union to form ABC type data and " Total" table ‘Name select’.
Row Subtotal second =
IF (
SELECTEDVALUE ( '‘Name select’'[Name] ) = " Total",
CALCULATE ( SUM ( ’Row Table’[Value] ), ALL ( '‘Name select’'[Name] ) ),
SUM ( ’Row Table’[Value] )
)
Result:
Step analysis:
When ‘Name select’ '[Name] Selected data " Total" when the value of the Value will be summed according to Date, otherwise, it returns the current value of.
Column Subtotal:
‘Date select’ =
UNION (
DISTINCT ( ’Column Table’[Date] ),
DATATABLE ( "Date", STRING, { { " Total" } } )
)
Result:
Step analysis:
Use distinct to de-duplicate the name in the table ‘Column Table’, use datatable() to create data containing " Total" in the date column, and perform union to form 2020/1/1 date type data and" Total" table ‘Date select’.
Column Subtotal second =
IF (
SELECTEDVALUE ( ’Date select’'[Date] ) = " Total",
CALCULATE ( SUM ( ’Column Table’[Value] ), ALL ( ’Date select’'[Date] ) ),
SUM ( ’Column Table’[Value] )
)
Result:
Step analysis:
When ‘Date select’'[Date] Selected data " Total" when the value of the Value will be summed according to name, otherwise, it returns the current value of.
Output:
This is the expected table chart.
The blank character before the " Total" makes it the first column in the Matrix because the columns in the Matrix of Power BI are sorted in ascending order from the first character.
We can verify if the results are correct by adding the data.
Add the following data to the two original tables:
Row Subtotal:
Column Subtotal:
The results of the matrix are as follows:
The result is the same as I expected.
Please refer to the attachment below for details.
I hope this article can help you with the similar question.
Author: Yang Liu
Reviewer: Ula Huang, Kerry Wang
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.