Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
So I have the following problem and I need help with it using Dax measures only. The data looks like this:
Recipe | Ingredient | Cuisine |
Hummus | Chickpeas | Syrian |
Hummus | Tahini | Syrian |
Hummus | Oil | Syrian |
Hummus | Chickpeas | Lebanese |
I want to calculate the ratio of ingredients to recipes depending on in how many cuisines do they appear together.
For example: the result should first be like:
Recipe | Ingredient | # Cuisines |
Hummus | Chickpeas | 2 |
Hummus | Tahini | 1 |
Hummus | Oil | 1 |
And then finally the ratio of ingredients to recipes should be 1.33 since it's the sum of cuisines divided by number of ingredients.
But the biggest problem is that some of these rows are duplicates since there are other columns as well. Because of that I could not simply take the distinct count of cuisine and I ended up with a ratio of 0.66 finally. I hope I am being clear enough here.
How could I achieve this using measures only?
Thanks in advance.
Hi, @Anonymous
try below code just adjust your table and column name.
result =
var a = CALCULATE(COUNT('table 1'[Cuisine]),ALL('table 1'))
var b = CALCULATE(DISTINCTCOUNT('table 1'[Ingredient]),ALLEXCEPT('table 1','table 1'[Recipe]))
return
divide(a,b)
User | Count |
---|---|
14 | |
11 | |
6 | |
6 | |
5 |
User | Count |
---|---|
29 | |
17 | |
11 | |
7 | |
5 |