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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Calculating the ratio of ingredients using measures only

So I have the following problem and I need help with it using Dax measures only. The data looks like this:

RecipeIngredientCuisine
HummusChickpeasSyrian
HummusTahiniSyrian
HummusOilSyrian
HummusChickpeas

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:

 

RecipeIngredient# Cuisines
HummusChickpeas2
HummusTahini1
HummusOil1

 

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.

1 REPLY 1
Dangar332
Super User
Super User

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)

 

Dangar332_0-1698484404173.png

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.