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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
dkernen2
Helper I
Helper I

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 I
Helper I

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.