The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello,
I'm new to Power BI and can't wrap my head around this. I attached a sample table closely related to what I'm trying to figure out.
Table1
Customer Name | Food Group |
Aaron | Fruit |
Bill | Fruit |
Chris | Meat |
Chris | Vegetable |
Derek | Vegetable |
Derek | Fruit |
Eric | Vegetable |
Francine | Meat |
Francine | Fruit |
Francine | Vegetable |
How would I count the number of unique customers that only have a food group that is either fruit or vegetable, or both. For example, Aaron, Bill, Derek, Eric would be considered, so 4 total.
Also, how would I count the number of unique customers that have a food group that is meat and either fruit or vegetable or both. In this case, only Chris and Francine is considered, in total of 2 customers.
Thank you!
Solved! Go to Solution.
Hi,
Dowload my PBI file from here.
Hope this helps.
Hello all,
I tried all of your solutions to my real dataset but the second measure for counting a food group that is meat and either fruit or vegetable or both doesn't account for a customer that has 2 or more of each. For example,
Table1
Customer Name | Food Group |
Aaron | Fruit |
Bill | Fruit |
Chris | Meat |
Chris | Vegetable |
Derek | Vegetable |
Derek | Fruit |
Eric | Vegetable |
Francine | Meat |
Francine | Fruit |
Francine | Vegetable |
George | Meat |
George | Meat |
George | Vegetable |
George | Fruit |
Heather | Meat |
Heather | Meat |
Isabel | Fruit |
Isabel | Meat |
Isabel | Fruit |
Isabel | Fruit |
Joe | Meat |
Joe | Meat |
Joe | Vegetable |
Kevin | Meat |
In this updated table, George, Isabel and Joe should be considered in the second measure.
Also, since there is a total of 11 unique customers and Heather and Kevin doesn't fit in either measures, (1st measure has Aaron, Bill, Derek, Eric {4 total}), (2nd measure has Chris, Francine, George, Isabel, Joe {5 total}, is it correct to assume that the difference between the total unique customers and sum of both the measures is the total number of customers that only have a food group of meat, which is 2 in this case (Heather, Kevin)?
In my real dataset, it is substantially bigger, so the difference isn't clearer to me if I could make that assumption.
Thank you!
Hi,
Dowload my PBI file from here.
Hope this helps.
Thank you. This is what I was looking for!
You are welcome.
Hi,
You may download my PBI file from here.
Hope this helps.
Hi,
please check the below picture and the attached pbix file.
Question one measure: =
VAR newtable =
SUMMARIZE (
FILTER ( Data, Data[Food Group] IN { "Fruit", "Vegetable" } ),
Data[Customer Name]
)
VAR othertable =
SUMMARIZE (
FILTER ( Data, Data[Food Group] IN { "Meat" } ),
Data[Customer Name]
)
VAR resulttable =
EXCEPT ( newtable, othertable )
RETURN
CONCATENATEX ( resulttable, Data[Customer Name], ", " ) & " / "
& COUNTROWS ( resulttable )
Question two measure: =
VAR newtable =
SUMMARIZE (
FILTER ( Data, Data[Food Group] IN { "Fruit", "Vegetable" } ),
Data[Customer Name]
)
VAR othertable =
SUMMARIZE (
FILTER ( Data, Data[Food Group] IN { "Meat" } ),
Data[Customer Name]
)
VAR resulttable =
INTERSECT( newtable, othertable )
RETURN
CONCATENATEX ( resulttable, Data[Customer Name], ", " ) & " / "
& COUNTROWS ( resulttable )
you can try this
Proud to be a Super User!
User | Count |
---|---|
74 | |
70 | |
39 | |
30 | |
28 |
User | Count |
---|---|
104 | |
95 | |
51 | |
48 | |
46 |