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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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