Forum Discussion
BrianNeedsHelp
Resolver I
1 year agoCount Rows in Visual
I want to count rows in a Matrix visual. The row count would change based on what is selected in the slicers. I want to put the count in a card that will change dynamically based on what is select...
- 1 year ago
Hi,
I am not sure if I understood your question correctly, but I think we can try using numeric parameter something like below. Please check the below picture and the attached pbix file.
Or, please share your sample pbix file's link to help me to have a bit more clear understanding.Use parameters to visualize variables - Power BI | Microsoft Learn
OwenAuger
Super User
1 year agoYou would need to do something like this:
- Create a measure that constructs a table containing the same columns/measures as the matrix visual, and counts the rows.
- Place that measure on a card visual and ensure the same slicers are filtering both the matrix and card.
Explanation:
- Matrix visuals generate queries using SUMMARIZECOLUMNS behind the scenes, which you can capture and examine using Performance Analyzer (see here).
- With default settings, the number of rows in a matrix (and returned by SUMMARIZECOLUMNS) depends on the combinations of row fields for which at least one measure is nonblank in at least one column.
- To create your row count measure, you can take the SUMMARIZECOLUMNS component of the query and simplify/modify to produce the number of rows you actually need, depending whether you want to include subtotals etc. Then count the rows of the resulting table.
Simple example (PBIX attached):
- Assume we have a matrix containing Country and Brand on rows, and Sales Amount as the only measure.
- The matrix does not include subtotals or grand total.
- We can then create this measure to count the rows and display on a card visual:
Matrix Row Count - Country|Brand|Sales Amount =
COUNTROWS (
SUMMARIZECOLUMNS (
'Product'[Brand],
Customer[Country],
"Sales Amount", [Sales Amount]
)
)
Notes:
- The measure assumes specific row/column/measure fields are used in the visual.
- This would need to be modified if subtotal rows are to be included or if fields are placed in columns rather than rows.
Regards