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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
BugmanJ
Helper V
Helper V

Finding Sum of Minimum Values from Multiple Groups

Good Day All,

 

In this example, I have:

  • Baker Name
  • Type of Food
  • For Each Baker, an ingredient list with ingredient code and price. There are several similar ingrediants, each with a different code and price which could fit into the below ingredient groups
  • A code matrix. For instance, Selecting from food "Tray Bake" means there are two ingredient groups

What I want:

  • Upon selecting the food, PowerBi should give a total cost for each baker for that food using the cheapest ingriedant in that group.

As an example, if we select "Tray Bake", then from the food Matrix:

 

Desciption GeneralFoodIngriendantCode 1Code 2Code 3Code 4
MilkTray BakeIngrediant 145H19G7FGCM5
MargarineTray BakeIngrediant 22F35L  

 

Now just looking at a single Baker:

Ingredient CodeDescriptionCostBaker
45HCows Milk5.10Jsho
35LMargarine (Dairy Free)6.00Jsho
19GMilk (Lactose Free)1.10Jsho
7FGGoats Milk1.50Jsho
2FMargarine (Creamy)4.80Jsho
CM5Chocolate Milk1.25Jsho

 

Now the minimum for each ingrediant:

Desciption GeneralFoodIngriendantCost
MilkTray BakeIngrediant 11.10
MargarineTray BakeIngrediant 24.80

 

Which should then just give us in the final table

BakerFoodCost
JSHOTray Bake5.90

 

Some bakers can not do all the ingriedants and should therefore be excluded for that selection.

There is also in there discount and region but thats for another day.

 

Can this be done in PowerBI? I have it working beautfilly in Tableau but have been asked to look at it for Powerbi. In reality there is several thousand lines, but the above is a good example using dummy data.

 

Link to dummy data: https://we.tl/t-Ffi8e1Y4y1 

Thank you

J

2 REPLIES 2
BugmanJ
Helper V
Helper V

Hi @v-yanjiang-msft ,

Thanks, but there is a problem. In my original request, i noted that bakers whom could not provide all the ingriendants should not end up in the final table, but in your example, bakers whom are not providing all the ingriendants are still ending up in the table.

Do you have a solution for this otherwise your work is spot on (for the calculation)

Thanks

v-yanjiang-msft
Community Support
Community Support

Hi @BugmanJ ,

According to your description, here's my solution.

1.In Power BI, the data model is very important for computing, one table per baker in your sample, it should append in Power Query. Select Append Queries>Append Queries as New.

vkalyjmsft_0-1652090980177.png

Add all baker tables and select OK, the new table is renamed "Ingredient" in my sample.

vkalyjmsft_1-1652091034634.png

2.Create a new table.

vkalyjmsft_2-1652091252047.png

Table = GENERATE('Code Matrix',VALUES('Bakers'[Bakers]))

Make relationship like this:

vkalyjmsft_3-1652091329885.png

3. Create a calculated column in the new table.

Cost =
MINX (
    FILTER (
        ALL ( 'Ingredient' ),
        'Ingredient'[Baker] = EARLIER ( 'Table'[Bakers] )
            && 'Ingredient'[Ingredient Code]
            IN { 'Table'[Code 1], 'Table'[Code 2], 'Table'[Code 3], 'Table'[Code 4] }
    ),
    'Ingredient'[Cost]
)

Get the correct result.

vkalyjmsft_4-1652091406943.png

Another method also can get the correct answer at the ingriendant level without create new calculated table.

Create a measure.

Cost =
MINX (
    FILTER (
        ALL ( 'Ingredient' ),
        'Ingredient'[Baker] = MAX ( 'Bakers'[Bakers] )
            && 'Ingredient'[Ingredient Code]
                IN {
                    MAX ( 'Code Matrix'[Code 1] ),
                    MAX ( 'Code Matrix'[Code 2] ),
                    MAX ( 'Code Matrix'[Code 3] ),
                    MAX ( 'Code Matrix'[Code 4] )
                }
    ),
    'Ingredient'[Cost]
)

vkalyjmsft_6-1652091630941.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors