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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
BriefStop
Frequent Visitor

Measure to find value that appears most frequently(mode) filtered by multiple categories

OrderRestaurantMealItem
1ABreakfastEggs
2ABreakfastEggs
3ABreakfastPancakes
4ADinnerSteak
5ADinnerSalad
6ADinnerSteak
7ALunchSalad
8ALunchSalmon
9BBreakfastToast
10BBreakfastToast
11BBreakfastJuice
12BLunchSalad
13BLunchSalad


I'm trying to find the most frequently ordered item on the menu for a specific meal for a restaurant(eg. For restaurant A, meal Breakfast, Eggs is the most frequently ordered item)

I've been trying to use a mix of different posts such as this one and the following:

FIRSTNONBLANK (
    TOPN (
        1,
        VALUES ('Table'[Item] ),
        RANKX( ALL( 'Table'[Item]), 'Table'[Item]],,DESC)
    ),
    1
)

However the problem is that I need to be able to do this for multiple filters for the calculation:
Filter 1: Filter for only Restaurant A
Filter 2: Filter for only Breakfast/Dinner/Lunch which will be linked to a slicer
 
How can I incorporate these two filters into a measure to find the most frequently ordered item for a specific restaurant and meal?
1 REPLY 1
TomMartens
Super User
Super User

Hey @BriefStop ,

 

here you will find a pbix that contains a solution (have a lookt at the page Restaurants, Meals, and Items): https://tommartens-my.sharepoint.com/:u:/g/personal/tom_minceddata_com/EYqyDRiNiQpMkiZWZI5V5ocB5Bx0S...

 

I created this DAX measure:

most Frequent Item = 
// IF( HASONEVALUE( 'Table (2)'[Restaurant] ) && HASONEVALUE('Table (2)'[Meal] )

//     ,
    var currentRestaurant = SELECTEDVALUE( 'Table (2)'[Restaurant] )
    var currentMeal = SELECTEDVALUE( 'Table (2)'[Meal] )
    var t = 
        SUMMARIZE(
            ALLSELECTED( 'Table (2)' )
            , 'Table (2)'[Restaurant]
            , 'Table (2)'[Meal]
            , 'Table (2)'[Item]
        )
    return
CONCATENATEX(
    TOPN(
        1
        , ADDCOLUMNS(
            FILTER(
                t
                , [Restaurant] = currentRestaurant && [Meal] = currentMeal
            )
            , "noOfItems"
                , var r = [Restaurant]
                var m = [Meal]
                return
                
                CALCULATE(
                    COUNT( 'Table (2)'[Item] )
                    , 'Table (2)'[Restaurant] = r
                    , 'Table (2)'[Meal] = m
                )
        )
        , [noOfItems]
        , DESC
        , [Meal]
        , ASC
    )
    , [Item]
    , ", "
    , [Item]
)

This allows to create this table visual:
image.png
Hopefully, this provides what you are looking for.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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