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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
msft-cap
Helper I
Helper I

Incorrect rows returned with countrows and filter function

I am using below DAX formulas to count the number of clients with Rating A to D. I am getting count as 8 even though the number of records is 5.

Any thoughts on what is going wrong here.

 

Client_count = Countrows(filter('ClientDetail','ClientDetail'[ClientRating] in { "A", "B", "C","D"}))

1 ACCEPTED SOLUTION

Hi @msft-cap ,

 

Please make sure whether there are duplicate column combiantions like [Name] and [ClientRating] in your data model. 
For example: There may be two or more Name = C01 and ClientRating = C in your data model. Then you will count more than 5.

My Sample:

RicoZhou_0-1658218550852.png

In table visual I could only see five records, due to Power BI will only show duplicates once. Your measure will return 8 in my sample.

RicoZhou_2-1658218663229.png

Try this code.

Client_count =
COUNTROWS (
    SUMMARIZE (
        FILTER ( ClientDetail, 'ClientDetail'[ClientRating] IN { "A", "B", "C", "D" } ),
        ClientDetail[Name],
        ClientDetail[ClientRating]
    )
)

Result is as below.

RicoZhou_3-1658218814273.png

 

Best Regards,
Rico Zhou

 

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

 

 

 

View solution in original post

4 REPLIES 4
jcalheir
Solution Supplier
Solution Supplier

Hi

 

Try using a calculate function:

 

Client_count = 
CALCULATE(
    COUNTROWS('ClientDetail'),
    'ClientDetail'[ClientRating] in { "A", "B", "C","D"}
)

 

Kind regards,
José
Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 🙂

Jihwan_Kim
Super User
Super User

Hi,

I think your measure seems correct.

Please check the below picture and the attached file.

I tried to create a sample pbix file like below. If your data model looks different, please share your sample pbix file's link here, and then I can try to look into it to come up with an accurate solution.

Thanks.

 

Picture4.png

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


@Jihwan_Kim My report has about 400 records and only 5 records has clientRating either C or D. rest all are null. When I added the ClientRating field to table format, I get 5 records and rest all records has null/blank. I am not sure why I keep getting 8 count with the above DAX formula. 

I am unable to share report due to data confidentiality and mock up example just work fine as you shared. 

Hi @msft-cap ,

 

Please make sure whether there are duplicate column combiantions like [Name] and [ClientRating] in your data model. 
For example: There may be two or more Name = C01 and ClientRating = C in your data model. Then you will count more than 5.

My Sample:

RicoZhou_0-1658218550852.png

In table visual I could only see five records, due to Power BI will only show duplicates once. Your measure will return 8 in my sample.

RicoZhou_2-1658218663229.png

Try this code.

Client_count =
COUNTROWS (
    SUMMARIZE (
        FILTER ( ClientDetail, 'ClientDetail'[ClientRating] IN { "A", "B", "C", "D" } ),
        ClientDetail[Name],
        ClientDetail[ClientRating]
    )
)

Result is as below.

RicoZhou_3-1658218814273.png

 

Best Regards,
Rico Zhou

 

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

 

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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