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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.