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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
StephenClarke
Frequent Visitor

Return highest sales value Product per Client

Dear Community,

 

I have a large table of sales transaction datafor all our cleints and all the respective products of ours they have purchased over time.

I would like some DAX to add a column and tag each client with a prefered product which i have defined as the product they have spent the most on over their lifetime with the company.

 

ClientProductValueDESIRED NEW COLUMN
Prefered Product
111A5A
112B5B
111A5A
112B5B
111B5A
112A5B

 

I have attempted the following:

 

Top Programme =
VAR ClientID = Booking[ClientID]
VAR ProductID =
SUMMARIZE(FILTER(Booking, Booking[ClientID] = ClientID),
Booking[Brochure_ID],
"ProdCount", SUM(Booking[Total_Headline_Value])
)
RETURN
SELECTCOLUMNS(
TOPN( 1, ProductID, [ProdCount]),
"Client ID", Booking[Brochure_ID]
)
 
But get the error:
A table of multiple values was supplied where a single value was expected.
 
In the case of ties i would be happy to go arbitarily with the first or last record. Whatever makes the code easier.
 
Help!
1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@StephenClarke 

You can add the following column to get the desired result. I found additional columns in your formula that was not in the sample data you provided, I hope you can adjust the following formula to suit your columns,

 

Top Programme = 
var __Client = Booking[ClientID]
var ClientProductAmount = 
        TOPN(1,
            ADDCOLUMNS(
                SUMMARIZE(
                    FILTER(Booking, Booking[ClientID] = __Client),
                    Booking[Product]
                ),
                "Amount", CALCULATE(SUM(Booking[Value]))
            ),
            [Amount]
        )
return
    MAXX(ClientProductAmount,Booking[Product])

 

Fowmy_0-1620514423289.png

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

3 REPLIES 3
StephenClarke
Frequent Visitor

Genius! 

Thank you so much for the replies.

Ashish_Mathur
Super User
Super User

Hi,

Do you want a measure or a calculated column formula?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Fowmy
Super User
Super User

@StephenClarke 

You can add the following column to get the desired result. I found additional columns in your formula that was not in the sample data you provided, I hope you can adjust the following formula to suit your columns,

 

Top Programme = 
var __Client = Booking[ClientID]
var ClientProductAmount = 
        TOPN(1,
            ADDCOLUMNS(
                SUMMARIZE(
                    FILTER(Booking, Booking[ClientID] = __Client),
                    Booking[Product]
                ),
                "Amount", CALCULATE(SUM(Booking[Value]))
            ),
            [Amount]
        )
return
    MAXX(ClientProductAmount,Booking[Product])

 

Fowmy_0-1620514423289.png

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.