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
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
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

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.