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
pschommer
Helper II
Helper II

Combined item sales

My situation is something like the following:

Clothing seller wants to know what combination of shirts are sold together. One table (SALES) exists to track all sales. I want to be able to select 2 shirts from the same or different slicers (whichever method works) and see the count of sales and possibly other fields from SALES. We will know they are from the same order when they have the same date and time (ORDERDATE) + customer (CUSTOMER) + cashier (CASHIER).

 

Getting it to work with exactly 2 selections would be fantastic and completely acceptable. Allowing for an unknown number (n>1) of selections would be the perfect solution.

 

Does anyone have an idea of how to approach this problem?

1 ACCEPTED SOLUTION

@pschommer,

Create a orderid column in SALES table using the DAX below.

orderid = CONCATENATE(SALES[CASHIER],CONCATENATE(SALES[CUSTOMER],SALES[ORDERDATE]))

Then create the OrderID table with the following DAX.
1.PNG

After that, create a relationship between SALES table and the new OrderID table using the ordered column, and you will get expected result by creating three custom columns(Red, Blue and White) following smoupre's suggestion.

OrderID Table = DISTINCT(SALES[orderid])

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Greg_Deckler
Super User
Super User

Can you provide sample data? The structure of your Sales table is going to determine how best to achieve this.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

I kept it simple. Something like THIS.

 

If I'm looking at it correctly...

  • RED+BLUE should have 4 combination sales (Customers Bob, Brian, Rick, Mary)
  • WHITE+RED should have 3 combination sales (Customers Monica, Rick, Mary)
  • BLUE+WHITE should have 4 combination sales (Customers Patrick, Rick, Lori, Mary)

Bonus points for...

  • RED+WHITE+BLUE having 2 combinations (Rick & Mary)

 

Not sure about slicers, but you could do it with filters.

 

Basically, create an OrderID table that has a unique key for your order ids. Create a related custom column in your sales table. I just concatenated your three values together.

 

Relate the tables. In your OrderID table create these columns:

 

Red = CALCULATE(SUM(Sales[Quantity]),FILTER(RELATEDTABLE(Sales),[ItemDesc] = "Red Shirt"))

Blue = CALCULATE(SUM(Sales[Quantity]),FILTER(RELATEDTABLE(Sales),[ItemDesc] = "Blue Shirt"))

White = CALCULATE(SUM(Sales[Quantity]),FILTER(RELATEDTABLE(Sales),[ItemDesc] = "White Shirt"))

Create a table visualization based on the OrderID table and put OrderID in it. Add a filter for Red is not Blank and Blue is not Blank. You will get your four orders. Add a filter for White is not blank. You get your two orders, etc.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thank you for your reponse. A quick clarification, if I may.

 

On the SALES table, I can create the concatenated OrderID field.

On the new OrderID table, how do you create unique key values (that I think you want to match with the concatenated values from SALES) when you don't know what those values are? New values are being created all the time and you won't know part of OrderID (Customer name).

 

I think I understand the rest of your suggestion. Does my question make sense?

@pschommer,

Create a orderid column in SALES table using the DAX below.

orderid = CONCATENATE(SALES[CASHIER],CONCATENATE(SALES[CUSTOMER],SALES[ORDERDATE]))

Then create the OrderID table with the following DAX.
1.PNG

After that, create a relationship between SALES table and the new OrderID table using the ordered column, and you will get expected result by creating three custom columns(Red, Blue and White) following smoupre's suggestion.

OrderID Table = DISTINCT(SALES[orderid])

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you to @v-yuezhe-msft and @Greg_Deckler for walking me through this.

 

The New Table definition based on a function that points to a different table is the unexpected learning for me in this exercise. Although I definitely needed every bit of advice to make it all work. Now that I have this simple example working properly, I will see if I can get it to work with my real dataset.

 

Your efforts are appreciated!

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.