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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
slsusan
Frequent Visitor

Maximum of sum by category for each customer id

Hi there, 

 

I have the following problem:

I have a customer table and a product table. A product can bought by only one customer, i.e. unique products. 

The product table shows the category of the product, the customer who bought the product and the profit which was made by selling the product. 

For each customer, I would like to show the category which the customer is exposed to most, i.e. first get the sum of profit for each category the customer makes purchases in, and then get the category, where the customer has produced the maximum profit with. 

Example in attatched tables: 

Customer 1:  MAX(SUM(profit in cat 1), SUM(profit in cat 3))= MAX(14, 5)=14

Customer 2: MAX(SUM(profit in cat 4))= MAX(2)=2

Customer 3: MAX(SUM(profit in cat 2))= MAX(3)=3

and so on for each customer...

 

Can you help me to create a measure which outputs the above calculation for the customer table?

I am looking forward to your support! 

 

Kind regards

Susanne

          

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@slsusan assuming you already have a relationship between these two tables on the Customer column which will be on to many, add the following two columns in the Customer table:

 

Max Profit = 
VAR __t = RELATEDTABLE ( 'Product' )
RETURN
MAXX ( __t, [Profit] )

Most Profitable Category = 
VAR __t = RELATEDTABLE ( 'Product' )
RETURN
CALCULATE ( MIN ( 'Product'[Category] ), TOPN ( 1, __t, [Profit], DESC ) )

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

5 REPLIES 5
parry2k
Super User
Super User

@slsusan assuming you already have a relationship between these two tables on the Customer column which will be on to many, add the following two columns in the Customer table:

 

Max Profit = 
VAR __t = RELATEDTABLE ( 'Product' )
RETURN
MAXX ( __t, [Profit] )

Most Profitable Category = 
VAR __t = RELATEDTABLE ( 'Product' )
RETURN
CALCULATE ( MIN ( 'Product'[Category] ), TOPN ( 1, __t, [Profit], DESC ) )

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@slsusan what is the expected result for each customer:

 

for customer 1, will it be category 1 and profit 10, and for customers 2 and 3, just whatever category and profit value since they have only one row of data? Is this what you want?

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Dear @parry2k ,

 

thank you for your reply. 

For each customer, we want to determine the most profitable category. 

If there is only one category, of which a customer has bought a product, it is clear, that this category is the most profitable one (customer 2 -> category 4, profit=2, cutomer 3 ->category 2, profit=3). 

Each customer is in at least one category, else it would not be a customer anyways. 

Has my situation become more understandable?

 

Best regards

Susanne 

parry2k
Super User
Super User

@slsusan Read this post to get your answer quickly.

https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Dear @parry2k , dear all,

 

I have forgotten to attatch my example data files, here they are.

Further, I would like to get the max exposed category as well as the profit of it for each customer. 

The categories are supposed to be chosed by a filter.

Thanks! 

 

Customer tableCustomer tableProduct tableProduct table

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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