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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Grevatious
Frequent Visitor

Categorize Orders based on the product

Hello everyone,

 

I have a dataset that contains a lot of transaction, each of them detailed. This means that there is a row for every product within an order, like this:

 

OrderSku Name
1Product A
1Product B
2Donation A
3Product C
3Donation B
4Donation A
4Donation B

 

Now I'm trying to create a calculated column that could help me identify the Type of order like this: 

 

OrderSku NameType of Order
1Product ASales
1Product BSales
2DonationDonation
3Product CMixed
3DonationMixed
4DonationDonation
4DonationDonation

 

I have been trying using EARLIER but I can only get Sales and Donations identified, I don't know how to identify the orders that contains both Donations and normal Products.

 

Thank you!!

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@Grevatious Usually in scenarios like this you have a product table with a unique record and have relationship with sales, and that product table will have type of product like Donatoins or Sales

 

Anyhow, add following two columns in your table and it should work.

 

Type = IF ( CONTAINSSTRING( 'Table'[Sku Name], "Donation" ), "Donation", "Sales" )


Order Type = 
VAR __c = CALCULATETABLE( VALUES ( 'Table'[Type] ), ALLEXCEPT('Table', 'Table'[Order] ) ) 
RETURN
SWITCH ( TRUE(),
    COUNTROWS( __c ) > 1, "Mixed",
    __c
) 

 

First column is to get type of the product,  if this information is in product table then it can be used from there.

 

Would appreciate Kudos 🙂 if my solution helped. 



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

2 REPLIES 2
amitchandak
Super User
Super User

@Grevatious ,

Try a new column like

New column =
var _all = countx(filter(table,table[Order]=earlier(Table[Order])),table[Order])
var _sales = countx(filter(table,table[Order]=earlier(Table[Order]) && [Type of Order] = "Sales"),table[Order])
var _don = countx(filter(table,table[Order]=earlier(Table[Order]) && [Type of Order] = "Donation"),table[Order])
return
switch(true(),
_all =_sales , "Sales",
_all =_don , "Donation",
"Mixed"
)
parry2k
Super User
Super User

@Grevatious Usually in scenarios like this you have a product table with a unique record and have relationship with sales, and that product table will have type of product like Donatoins or Sales

 

Anyhow, add following two columns in your table and it should work.

 

Type = IF ( CONTAINSSTRING( 'Table'[Sku Name], "Donation" ), "Donation", "Sales" )


Order Type = 
VAR __c = CALCULATETABLE( VALUES ( 'Table'[Type] ), ALLEXCEPT('Table', 'Table'[Order] ) ) 
RETURN
SWITCH ( TRUE(),
    COUNTROWS( __c ) > 1, "Mixed",
    __c
) 

 

First column is to get type of the product,  if this information is in product table then it can be used from there.

 

Would appreciate Kudos 🙂 if my solution helped. 



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.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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