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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
dkernen2
Helper II
Helper II

Create a DISTINCTCOUNT and show that total on every row

I need a little help.  I have a DAX Measure that counts the number of unique vendors: 

DISTINCTCOUNT(TABLE[Vendor ID])

What I need to do is to put that distinct count on every row of the matrix (that meets my year filter).
 
Simple example where I have three years that meet my years slicer but I have two distinct vendors and I need that 2 on every row.
CategoryYearVendorDISTINCT (have)DISTINCT TOT (need)
A2018ABC12
A2019DEF12
A2020DEF12
Total  22
https://kauffman.box.com/s/2n6ccf18xkfzrmxopltujibbasxeqbrr

Thank you in advance!

1 ACCEPTED SOLUTION

This may be overkill, but it works:

VAR _curID = MAX(TABLE[Category ID])
VAR _yrmin = CALCULATE(MIN('Review Years'[Review Year]),ALLSELECTED('Review Years'[Review Year]))
VAR _yrmax = CALCULATE(MAX('Review Years'[Review Year]),ALLSELECTED('Review Years'[Review Year]))
VAR _uniq = CALCULATE([Vendor Count],
   FILTER(ALL(TABLE),
     TABLE[Category ID] = _curID &&
     TABLE[Review Year] >=_yrmin &&
     TABLE[Review Year] <=_yrmax))
RETURN _uniq

View solution in original post

4 REPLIES 4
dkernen2
Helper II
Helper II

Thank you!  That gave me the total for ALL vendors in my table, not vendors related to each category.  I think I need to do something with ALLSELECTED for the years given for the current category.

Ah, okay! I misunderstood your requirement. You could use ALLEXCEPT and then put the column name in that you want it to still filter by. So, 

CALCULATE(DISTINCTCOUNT(TABLE[Vendor ID]),ALLEXCEPT(TABLE,TABLE[Vendor ID]))

This may be overkill, but it works:

VAR _curID = MAX(TABLE[Category ID])
VAR _yrmin = CALCULATE(MIN('Review Years'[Review Year]),ALLSELECTED('Review Years'[Review Year]))
VAR _yrmax = CALCULATE(MAX('Review Years'[Review Year]),ALLSELECTED('Review Years'[Review Year]))
VAR _uniq = CALCULATE([Vendor Count],
   FILTER(ALL(TABLE),
     TABLE[Category ID] = _curID &&
     TABLE[Review Year] >=_yrmin &&
     TABLE[Review Year] <=_yrmax))
RETURN _uniq
nsexton12
Resolver II
Resolver II

You can use the calculate function in combination with the ALL function. So, 

 

CALCULATE(DISTINCTCOUNT(TABLE[Vendor ID]),ALL(TABLE))

Please mark as a solution if this works for you!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.