Reputation: 337
I'm new to DAX and Power BI. I'm having trouble filtering something that is probably not very complicated but I've finally given up. Any assistance is appreciated.
My starting data looks like this. I want to distinctcount how many drugs each person got (3 for Amy and 2 for Willy), then filter by 3.
Starting Data:
Key Name DOB OTC
AmyZ32874 Amy Z 1/1/1990 Motrin
AmyZ32874 Amy Z 1/1/1990 Tylenol
AmyZ32874 Amy Z 1/1/1990 Bayer
WillyV32906 Willy V 2/2/1990 Motrin
WillyV32906 Willy V 2/2/1990 Tylenol
WillyV32906 Willy V 2/2/1990 Tylenol
Desired Result: Ideally, this would be the desired result because the DisctinctCount of OTC is 3 for Amy Z.
Key Name DOB OTC
AmyZ32874 Amy Z 1/1/1990 Motrin
AmyZ32874 Amy Z 1/1/1990 Tylenol
AmyZ32874 Amy Z 1/1/1990 Bayer
Things I tried:
Thank you!!
Upvotes: 0
Views: 2320
Reputation: 2615
If you want a result set as a table in your post, then create a new table and paste this code:
TestTbl =
VAR SummaryTbl =
ADDCOLUMNS(
YourTbl,
"UniqueCount",CALCULATE(DISTINCTCOUNT(YourTbl[OTC]),ALLEXCEPT(YourTbl,YourTbl[Name]))
)
RETURN
FILTER(
SummaryTbl,[UniqueCount]=3)
Then Result:
Upvotes: 1
Reputation: 9052
Create a measure:
MyFilter :=
CALCULATE( DISTINCTCOUNT( Table1[OTC] ), ALLEXCEPT( Table1, Table1[Name] ) )
then drag this into the Filters pane and set it equal to your desired value, e.g. 3.
Upvotes: 1