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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
aiweller
Frequent Visitor

Count number of rows after a filter is applied

 

Hi,

 

I've been trying to find a solution with the below scenario. I hope someone can help.

 

I want to get the number of rows in Table1 filtered by the "Value" field in Table2. I've created a custom column in Table2 to input the values. 

I use the code "Count of Value = CALCULATE(COUNTROWS(Table1),FILTER('Table1','Table1'[Value]=Table2[Value]))" and it gets what I want. However, if I do filters on Table1 on the report, the values do not change. How do I link the values based on the filters selected?

 

Thanks,

Ashley

 

Table1.PNGTable2.PNG

1 ACCEPTED SOLUTION

@aiweller,

Instead of count of rows as a calculated column, try creating a measure as follows

 

Count of Values = CALCULATE(COUNTROWS(Table3), FILTER(Table3, Table3[Value] = MAX(Table4[Value]) ))

This should give you the desired result

 

Regards,

Thejeswar

View solution in original post

8 REPLIES 8
Thejeswar
Resident Rockstar
Resident Rockstar

Hi @aiweller,

 

When you say "However, if I do filters on Table1 on the report, the values do not change" what do you mean?

 

From your post, I get that Table 1 is your source and Table 2 has a calculated column which is based on Table 1.

Now you are adding a filter on Table1 and your Table 1 is not getting filtered

 

Can you clarify a bit more on what is the filter you are talking about and what are the values?

 

It's better if you can give some sample data and your expected result

 

Regards,

Thejeswar

Hi @Thejeswar,

 

Thanks for the reply.. What I mean is if I filter let's say, Country I only select "US" or Department I only select "Finance", the values in the calculated column in Table2 does not get updated. I would like to have the Table2 column show the number of rows resulting from the filter.

 

For example, if I select County "US" in Table1, the number in "Count of Value" in Table2 should only show values "3A" as 1 and "1B" as 1. The rest is 0.

 

Hope this explains.

 

Ashley

Hi @aiweller

 

Do you have a relationship between your two tables ? If yes you need to change it so it become a bidirectionnal relation

Go to the relationtab, double blick on the link between the tables and change the direction

 

It should work 

 

- Quentin

Hi @quentin_vigne,

 

Thanks for the suggestion. If I do a relationship the values that do not have matching records do not show. I would like to have values that do not have any matching records as "0".

 

For instance if I do relationship between the tables based on the "Value" column from both tables, the value for "1A" will not show. It will look like below. Unless there is another way to display unmatched records on Table2. 🙂

 

relationship.PNG

 

Thanks,

Ashley

 

 

@aiweller

 

I've done this and it looks like it's working

 

 1st.PNG2nd.PNG

 

 

I've added Value and Count of Table2 on the table 

 

If you want to see 0 instead of blank add "+ 0" at the end of your formula that count row

Hi @quentin_vigne,

 

From your example, you have selected "US" and the departments "Finance" and "HR" is displayed, but the "Count of Values" is still counting the total number of "2A" in Table1. The expected result for "2A" should be 1 instead of 2(it is showing 2 because it's including the value from "France").

 

relationship2.PNG

 

 

Thanks,

Ashley

 

@aiweller,

Instead of count of rows as a calculated column, try creating a measure as follows

 

Count of Values = CALCULATE(COUNTROWS(Table3), FILTER(Table3, Table3[Value] = MAX(Table4[Value]) ))

This should give you the desired result

 

Regards,

Thejeswar

Hi @Thejeswar,

 

Thanks so much. Works perfectly as what I wanted to achieve.

 

Just to ask, do you know why the total is not showing? In the result below, the second table I added (+0) to the end of the code to show the rows that have no matching records.

 

count0.png

 

Regards,

Ashley

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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