Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Is there a way to add a query in Power Query in Transform Data for Power BI where it will count the rows in all the other queries in the data set?
Ideally it would be a way to iterate through and return all the row counts for all the queries. I'd like to have a way to see row counts after a data refresh all in one location (one query).
Thank you
Solved! Go to Solution.
Do you absolutely need this in Power Query? DAX can do a simple COUNTROWS measure.
But if you insist (and I do NOT recommend):
Duplicate one of the tables. Add a Custom Column with a literal value as the name of the table, like "Table 1". Now do a GROUP BY on that column, and Aggregate of COUNT. Do this for all tables. Finally, do a UNION of these tables (assuming all the column names are identical.
WHY is this approach NOT recommended? Because it DOUBLES your query load! You have to read each table source TWICE!
In DAX, you could try this: Create a DAX table using SUMMARIZE function that does a COUNTROWS. The add to that a ADDCOLUMNS DAX function. Finally, wrap this in a DAX UNION statement with other SUMMARIZE statements.
Sample DAX table that counts rows in 'Table1':
Proud to be a Super User! | |
You could just do
= Table.RowCount(Query1)+Table.RowCount(Query2)+...+Table.RowCount(QueryN)
--Nate
As a single line of M-Code:
List.Accumulate(
Record.FieldNames(#sections[Section1]),
0,
(x,y)=> try x + Table.RowCount(Expression.Evaluate(y,#shared)) otherwise x)
Depending on how you are using this, you may need to subtract Table.RowCount(#"Previous Step") from the value.
#sections[Section1] returns a list of the queries as a record
The try ... otherwise is to handle those queries that might not be returning Tables.
As a single line of M-Code:
List.Accumulate(
Record.FieldNames(#sections[Section1]),
0,
(x,y)=> try x + Table.RowCount(Expression.Evaluate(y,#shared)) otherwise x)
Depending on how you are using this, you may need to subtract Table.RowCount(#"Previous Step") from the value.
#sections[Section1] returns a list of the queries as a record
The try ... otherwise is to handle those queries that might not be returning Tables.
You could just do
= Table.RowCount(Query1)+Table.RowCount(Query2)+...+Table.RowCount(QueryN)
--Nate
Do you absolutely need this in Power Query? DAX can do a simple COUNTROWS measure.
But if you insist (and I do NOT recommend):
Duplicate one of the tables. Add a Custom Column with a literal value as the name of the table, like "Table 1". Now do a GROUP BY on that column, and Aggregate of COUNT. Do this for all tables. Finally, do a UNION of these tables (assuming all the column names are identical.
WHY is this approach NOT recommended? Because it DOUBLES your query load! You have to read each table source TWICE!
In DAX, you could try this: Create a DAX table using SUMMARIZE function that does a COUNTROWS. The add to that a ADDCOLUMNS DAX function. Finally, wrap this in a DAX UNION statement with other SUMMARIZE statements.
Sample DAX table that counts rows in 'Table1':
Proud to be a Super User! | |
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
10 | |
8 | |
7 | |
6 | |
6 |