Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago

Count rows in table visual

Hello, how to get the number of rows as the total value in a table visual since the data is from multiple tables? Appreciate any help!

Thank you

4 Replies

  • 123abc's avatar
    123abc
    Community Champion

    RowCount = COUNTROWS('YourTableName')

     

    Replace 'YourTableName' with the name of the table you want to count the rows for. You can find the table name in the Power BI Fields pane.

    1. Press Enter to create the measure.

    2. Once you've created the measure, you can add it to your table visual. Simply drag and drop the "RowCount" measure from the Fields pane onto the Values or Columns area of the table visual.

    This measure will display the total count of rows for the table visual you specified. When you add it to your table visual, you'll see the count displayed as a single value in your table.

    If your data is coming from multiple tables, you should create separate measures for each table that you want to count, following the same steps. This way, you can have individual row counts for each table in your report. 

     

    OR

     

    Assuming you have two tables, Table1 and Table2, and you want to count the rows in both of them:

    TotalRowCount = COUNTROWS(Table1) + COUNTROWS(Table2)

    You can expand this pattern to include additional tables by adding more COUNTROWS functions and summing them up.

    1. Go to the "Modeling" tab in the Power BI ribbon.

    2. In the "Calculations" group, click on "New Measure."

    3. In the formula bar, enter the DAX measure formula as shown above, taking into account all the tables you want to count.

    4. Press Enter to create the measure.

    5. Once you've created the measure, you can add it to your table visual by dragging and dropping the "TotalRowCount" measure onto the Values or Columns area of the table visual.

    This measure will display the total count of rows from all the specified tables in your table visual.

    Remember to adjust the DAX measure based on the actual table names and the number of tables you want to count rows for in your report.

     

    If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

     

    In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

  • christinepayton's avatar
    christinepayton
    Most Valuable Professional

    You can count whatever the primary key on the table is. Like if you have a table that shows customer ID, customer name, order quantity and sales amount, coming from 2+ tables, you would count the customer ID row as that would be what is making the rows unique.

     

    It's kind of hard to get it to show up in a table visual in a way that is visually appealing, because any row count is just going to return 1 on each row before you get to the total at the bottom... sometimes I'll turn off the alternating row color and set the font to white to match the background on the values for that column to make it look slightly less lame... the total will still show in the normal font color.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or if you are still confused about it, please feel free to let me know.

     

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

  • Hi,

    It will depend upon the fields that you have dragged to the visual.  Share the download link of the PBI file and show the expected result.