Distinctcount with filter based on current row value

ejheflin

New Member
Joined
May 22, 2015
Messages
12
I am stumped on a seemingly simple issue. I have a single table of transactions and I would like to add a calculated column for some quality control. I have ProductID column and a ProductName column. I want to flag any productids that have more than 1 unique ProductNames.

=CALCULATE(DISTINCTCOUNT([ProductName]),FILTER(Data,Data[ProductID]=[ProductID]))

Any idea where i'm going wrong, here? I am definitely open to suggestions. I realize that I can accomplish the same thing with a pivot table count but I am hoping to nest this in with a few other QC formulas to keep things tidy.

Thanks for any suggestions!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
You just need to add EARLIER around one of the Data[ProductID] references.
Within FILTER, EARLIER(Data[ProductID]) refers to the value in the outer row context of the original table, while Data[ProductID] refers to the value in the inner row context of the Data table being filtered.

Code:
=
CALCULATE(
    DISTINCTCOUNT(Data[ProductName]),
    FILTER(Data,Data[ProductID]=[B]EARLIER[/B](Data[ProductID]))
)

Another way of doing it:
Code:
=
CALCULATE(
    DISTINCTCOUNT(Data[ProductName]),
    ALLEXCEPT(Data, Data[ProductID])
)
 
Upvote 0
You just need to add EARLIER around one of the Data[ProductID] references.
Within FILTER, EARLIER(Data[ProductID]) refers to the value in the outer row context of the original table, while Data[ProductID] refers to the value in the inner row context of the Data table being filtered.

Code:
=
CALCULATE(
    DISTINCTCOUNT(Data[ProductName]),
    FILTER(Data,Data[ProductID]=[B]EARLIER[/B](Data[ProductID]))
)

Another way of doing it:
Code:
=
CALCULATE(
    DISTINCTCOUNT(Data[ProductName]),
    ALLEXCEPT(Data, Data[ProductID])
)
Wow, you nailed it. Now i need to go read up on this so i can understand it :rolleyes:
THANK YOU!
 
Upvote 0

Forum statistics

Threads
1,224,126
Messages
6,176,517
Members
452,733
Latest member
Gao87

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top