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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
DJBAJG
Helper III
Helper III

Return top product by sales for each producer

Hello

 

I'm trying to create a table/matrix visual that will display the name of a producer and the top product they've sold based on the total number of sales. I've included a sample dataset to give you an idea of what I've got and the expected output.

 

Thanks. 

 

TABLE
ProducerProductSales
Producer 1Product 110
Producer 1Product 220
Producer 1Product 130
Producer 1Product 340
Producer 2Product 150
Producer 2Product 260
Producer 2Product 370
Producer 3Product 180
Producer 3Product 290
Producer 3Product 2100
Producer 3Product 2110
Producer 3Product 3120
   
   
   
Desired Output
ProducerProduct 
Producer 1Product 1 
Producer 2Product 3 
Producer 3Product 2 

 

 

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @DJBAJG 

Try this:

1. Place Table1[Producer] in the rows of a visual table

2. Place this measure in the visual:

TopSeller =
VAR AuxTable_ =
    CALCULATETABLE (
        DISTINCT ( Table1[Product] );
        TOPN ( 1; Table1; CALCULATE ( SUM ( Table1[Sales] ); ALL ( Table1[Sales] ) ) )
    )
RETURN
    CONCATENATEX ( AuxTable_; [Product]; ", " )

  

Please mark the question solved when done and consider giving kudos if posts are helpful.

 

Cheers  Datanaut

View solution in original post

2 REPLIES 2
AlB
Community Champion
Community Champion

Hi @DJBAJG 

Try this:

1. Place Table1[Producer] in the rows of a visual table

2. Place this measure in the visual:

TopSeller =
VAR AuxTable_ =
    CALCULATETABLE (
        DISTINCT ( Table1[Product] );
        TOPN ( 1; Table1; CALCULATE ( SUM ( Table1[Sales] ); ALL ( Table1[Sales] ) ) )
    )
RETURN
    CONCATENATEX ( AuxTable_; [Product]; ", " )

  

Please mark the question solved when done and consider giving kudos if posts are helpful.

 

Cheers  Datanaut

Hi AIB

 

Thanks for the quick response. That seems to get me what I needed with the addition of a RETURN FIRSTNONBLANK to eliminate multiple products being returned.

 

Thanks again.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.