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
daan1887
New Member

Compare numbers of more than 2 rows

Hi everybody,

 

I would be happy if some anyone of you guys would have a solution for my issue.

 

I need to compare prices of up to 5 sellers for ~ 5000 products. The final output should tell the user who has the cheapest price on a product level. 

 

Any ideas? Data structure and two possible output variants can be found below (I would prefer the first output, as it is more detailed).

 

Thanks in advance

Daniel

 

My data structure looks like this:

Seller | Product Price
Seller 1 | Product 1 | 5,99
Seller 2 | Product 1 | 8,99
Seller 3 | Product 1 | 6,99
Seller 4 | Product 1 | 5,99
Seller 5 | Product 1 | 5,99
Seller 1 | Product 2 | 18,99
Seller 2 | Product 2 | 20,99
Seller 3 | Product 2 | 20,99
Seller 4 | Product 2 | 20,99
Seller 5 | Product 2 | 20,99
Seller 1 | Product 3 | 2,99
Seller 2 | Product 3 | 2,99
Seller 3 | Product 3 | 4,99
Seller 4 | Product 3 | 
Seller 5 | Product 3 | 4,99

 

Needed output:


Product | Cheapest Offer
Product 1 | Seller 1, Seller 4, Seller 5
Product 2 | Seller 1
Product 3 | Seller 1, Seller 2

 

 

Alternative output:

Product | Cheapest Offer
Product 1 | Multiple sellers
Product 2 | Seller 1
Product 3 | Multiple sellers

1 ACCEPTED SOLUTION
edhans
Super User
Super User

I used Excel to do this, but you can do it in Power BI just as easily. just depends on where your source data is.

 

This is best done in Power Query, not in DAX. This is the code:

 

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Seller", type text}, {"Product", type text}, {"Price", type number}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Price] <> null)),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Product"}, {{"All Rows", each _, type table}}),
    #"Added Min Price record" = Table.AddColumn(#"Grouped Rows", "Min Price", each Table.Min([All Rows], "Price")),
    #"Expanded Min Price" = Table.ExpandRecordColumn(#"Added Min Price record", "Min Price", {"Price"}, {"Price"}),
    #"Added Get Best Price table" = Table.AddColumn(#"Expanded Min Price", "Best Prices", each let BestPrice = [Price]
in Table.SelectRows([All Rows], each [Price] = BestPrice)),
    #"Added Get Seller Name" = Table.AddColumn(#"Added Get Best Price table", "Get Seller Name", each Table.SelectColumns([Best Prices], "Seller")),
    #"Added Transpose table" = Table.AddColumn(#"Added Get Seller Name", "Transpose Table", each Table.Transpose([Get Seller Name])),
    #"Added Table to List" = Table.AddColumn(#"Added Transpose table", "Seller Names", each Table.ToList([Transpose Table], Combiner.CombineTextByDelimiter(", "))),
    #"Expanded Seller Names" = Table.ExpandListColumn(#"Added Table to List", "Seller Names"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Seller Names",{{"Seller Names", type text}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Changed Type1",{"Product", "Seller Names"})
in
    #"Removed Other Columns"

I basically grouped all of the data by product and put everything in an All Rows table. I then worked with each column one at a time as tiny nested tables until I got the end result, then expanded the final result for the seller names, and deleted all of my intermediate work.

 

Download my Excel file if you want to step through it and see how it works. I assumed a null price was to be excluded and filtered that out immediately.

 

By the way - this happens to be pretty close to one of the examples in the excellent book Magic Tricks for Data Wizards, which is free. Highly recommended.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

6 REPLIES 6
Zubair_Muhammad
Community Champion
Community Champion

Impressive DAX formula @Zubair_Muhammad Smiley Happy

I've not messed with CONCATENATEX so I'll need to dig deeper into that one.

Side question: How did you upload a file? I'd rather attach files than links to my OneDrive account, but only see a photo/video button.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Hi @edhans

 

This is one of the priveleges of being a Super User Smiley Happy

 

Nice solution and Nice website

Keep up the good work


@Zubair_Muhammad wrote:

Hi @edhans

 

This is one of the priveleges of being a Super User Smiley Happy

 

Nice solution and Nice website

Keep up the good work


 

Ahhh.... I'm just a muggle on this site, not a super user, so that explains it. Smiley LOL



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
edhans
Super User
Super User

I used Excel to do this, but you can do it in Power BI just as easily. just depends on where your source data is.

 

This is best done in Power Query, not in DAX. This is the code:

 

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Seller", type text}, {"Product", type text}, {"Price", type number}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Price] <> null)),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Product"}, {{"All Rows", each _, type table}}),
    #"Added Min Price record" = Table.AddColumn(#"Grouped Rows", "Min Price", each Table.Min([All Rows], "Price")),
    #"Expanded Min Price" = Table.ExpandRecordColumn(#"Added Min Price record", "Min Price", {"Price"}, {"Price"}),
    #"Added Get Best Price table" = Table.AddColumn(#"Expanded Min Price", "Best Prices", each let BestPrice = [Price]
in Table.SelectRows([All Rows], each [Price] = BestPrice)),
    #"Added Get Seller Name" = Table.AddColumn(#"Added Get Best Price table", "Get Seller Name", each Table.SelectColumns([Best Prices], "Seller")),
    #"Added Transpose table" = Table.AddColumn(#"Added Get Seller Name", "Transpose Table", each Table.Transpose([Get Seller Name])),
    #"Added Table to List" = Table.AddColumn(#"Added Transpose table", "Seller Names", each Table.ToList([Transpose Table], Combiner.CombineTextByDelimiter(", "))),
    #"Expanded Seller Names" = Table.ExpandListColumn(#"Added Table to List", "Seller Names"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Seller Names",{{"Seller Names", type text}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Changed Type1",{"Product", "Seller Names"})
in
    #"Removed Other Columns"

I basically grouped all of the data by product and put everything in an All Rows table. I then worked with each column one at a time as tiny nested tables until I got the end result, then expanded the final result for the seller names, and deleted all of my intermediate work.

 

Download my Excel file if you want to step through it and see how it works. I assumed a null price was to be excluded and filtered that out immediately.

 

By the way - this happens to be pretty close to one of the examples in the excellent book Magic Tricks for Data Wizards, which is free. Highly recommended.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

@daan1887

 

You can use this MEASURE as well

 

Cheapest Offer =
CONCATENATEX (
    TOPN ( 1, VALUES ( Table1[Seller ] ), CALCULATE ( MIN ( Table1[Price] ) ), ASC ),
    [Seller ],
    ", "
)

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