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
Anonymous
Not applicable

Trying to get a count of distinct values in a column

Hi All,

 

Im trying to achieve a COUNTIF of the unique values within a specific column to be filter later in the dashboard.

I can use the formula comfortably in MS Excel (see image below)

 

abdalahmed_2-1627566117039.png

But trying to replicate this in power bi I am finding difficult. This is what I had done so far:

 

 

COUNTIF for Duplicate ID = 
VAR RowID = fact_food_license[pref]
RETURN
COUNTROWS(
    FILTER(
        ALL(fact_food_license),
        RowID = fact_food_license[pref]
    )
)

 

 

The error message I am receiving is: 

 

A single value for column 'ID' in table 'fact_food_license' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result..

 

Any assitance would be grateful!

1 ACCEPTED SOLUTION

@Anonymous 

pls try

calculate(countrows(fact_food_license),allexcept(fact_food_license,fact_food_license[pref]))

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
Samarth_18
Community Champion
Community Champion

Hi @Anonymous 

You can update your measure code with below code:-

COUNTIF for Duplicate ID = 
COUNTROWS(
    FILTER(
        ALL(fact_food_license),
        fact_food_license[pref] = MAX(fact_food_license[pref])
    )
)

Add your pref column along with above measure on your table visual.

 

Thanks,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Anonymous
Not applicable

Thanks for you response Samarth

 

Your solution is only returning the value: 1.

 

The anticipating results should be 1, 2 or 3

@Anonymous 

pls try

calculate(countrows(fact_food_license),allexcept(fact_food_license,fact_food_license[pref]))

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.