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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.