cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors