Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
primolee
Helper V
Helper V

Using column value as table name as a parameter to trigger a function

Hello everyone,

 

I have several queries that I would like to count their rows and store in a different table.

 

I have created a one-column table with the query names in the column.  I want to add a new column using Table.RowCount and use the query-name column as parameter.  Is there a way of achieving this?

 

Table NameRow Count
Query A 
Query B 
QueryC 

 

Thank you.

 

Best regards,

David

1 ACCEPTED SOLUTION
primolee
Helper V
Helper V

I got it working.

 

Create a new column using the following code:

Table.AddColumn(previousStepName, "RowCount", each Table.RowCount(Record.Field(#shared,[Table Name])))

 

However, I think #shared still does not work in BI Service, so alternative is to create a record listing function names:

tableList = [
     #"Query A" = #"Query A",
     #"Query B" = #"Query B",
     QueryC = QueryC,
],

 

Then, change #shared to tableList:

Table.AddColumn(previousStepName, "RowCount", each Table.RowCount(Record.Field(tableList,[Table Name])))

 

This will work on Power BI Service and refresh with no problem.

View solution in original post

3 REPLIES 3
primolee
Helper V
Helper V

I got it working.

 

Create a new column using the following code:

Table.AddColumn(previousStepName, "RowCount", each Table.RowCount(Record.Field(#shared,[Table Name])))

 

However, I think #shared still does not work in BI Service, so alternative is to create a record listing function names:

tableList = [
     #"Query A" = #"Query A",
     #"Query B" = #"Query B",
     QueryC = QueryC,
],

 

Then, change #shared to tableList:

Table.AddColumn(previousStepName, "RowCount", each Table.RowCount(Record.Field(tableList,[Table Name])))

 

This will work on Power BI Service and refresh with no problem.

ImkeF
Community Champion
Community Champion

Hi @primolee ,

this can be done, but if you want to refresh it in the service, you have to define an environment record (here is a link on how this can be done automatically, if you have a very large number of queries for example: Automatically create function record for Expression.Evaluate in Power BI and Power Query – The BIcco...)

 

You add a column with this formula:
Expression.Evaluate("Table.RowCount(" & [Table Name] & ")", [#"Query A" = #"Query A", #"Query B" = #"Query B", #"Query C" = #"Query C"])

If your query table names contain spaces, you have to adjust your table like so:

Table Name
#"Query A"
#"Query B"
#"Query C"

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Hello @ImkeF 

 

Thank you so much for your reply.  As you were replying, I also figure out using Record.Field.

Table.AddColumn(previousStepName, "RowCount", each Table.RowCount(Record.Field(#shared,[Table Name])))

 

And since #shared might still not work in Power BI Service refresh, simply create a table name record as what you wrote in your reply and it will work on BI Service.

 

Thank you once again for helping me again.  Thanks!

 

Best regards,

David

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.