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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Get the common value using calculate

Hello,

I have a restaurant dashboard where I have a table that contains each food along with its type, and I have to show for each type, a card with the dish that is most requested with its percentage.

Example: Spaghetti (75%) Lemon Juice (70%)

 

dish_nameid dish typedish type
spaghetti1main dish
spaghetti1main dish
spaghetti1main dish
icecream2dessert
lemon juice3drink
hamburger1main dish
water3drink
lemon juice3drink

 

Taking the example of spaghetti which corresponds to the main dish type, I have a measurement (maximum main course quantity) that returns the number of appearances.

What I need is that instead of having the number of appearances, have a measure that is the most requested main dish= Spaghetti.

 

Anyone know how to solve it? Thank you very much

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Here is one way to do it with a measure expression.

 

Top Dish =
CONCATENATEX (
    TOPN ( 1, VALUES ( Menu[dish_name] ), CALCULATE ( COUNTROWS ( Menu ) ), DESC ),
    Menu[dish_name],
    " "
)

 

If you put it in a table visual with the dish type column, this is the result

menu.png

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
Microsoft Employee

Here is one way to do it with a measure expression.

 

Top Dish =
CONCATENATEX (
    TOPN ( 1, VALUES ( Menu[dish_name] ), CALCULATE ( COUNTROWS ( Menu ) ), DESC ),
    Menu[dish_name],
    " "
)

 

If you put it in a table visual with the dish type column, this is the result

menu.png

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


lbendlin
Super User
Super User

Here's something to get you started.  it uses copious amounts of variables to show each step of the process.

 

This will only work if you show the dish type  grouped, and it will produce weird results for the totals.  i'll leave that up to you.

 

distribution = 
var a = distinct(Menu[dish_name])
var b = ADDCOLUMNS(a,"dish",Menu[dish_name],"total",count(Menu[dish_name]))
var c = ADDCOLUMNS(b,"dishcount",CALCULATE(count(Menu[dish_name]),filter(Menu,Menu[dish_name]=[dish])))
var d = ADDCOLUMNS(c,"percentage",DIVIDE([dishcount],[total]))
var e= topn(20,d,[dishcount],DESC)
var r= CONCATENATEX(e,[dish] & format([percentage]," (#%)"),",")
return r

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.