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
jmukhtar
Regular Visitor

First vs Second purchase Products

Hi

 

I am working on a requriement to generate visualize what products customer bought in second orders based on products that are purchased in first order and i am really struggling to get this working. 

 

If a 100 customers bought product A in first order and out of those 100 customers 50 bought Product B and 30 bought Product C and 20 bought Product D in second orders. This neeeds to be presented like this 

 

 

jmukhtar_1-1640589725348.png

 

Data that i currently have looks like this where sortorder is the first or second order number for the customer

 

 

Screenshot 2021-12-27 at 12.30.23.png

 

 

We have full control of data and have all of sales and product data available to us and can format data as we require. 

 

I have tried quite a few things but not able to get this working properly. 

 

Any help on how to do it would be really really helpful

 

Thanks,

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @jmukhtar ,

 

I have created a data sample,

Eyelyn9_0-1640832565524.png

According to this requirement: we are looking for a list of customers who have bought a specific product in first order and then use that list to see what these customers have bought in second order

 

Please follow these steps:

1. Create a productId table for slicer

ForSlicer = VALUES('Table'[ProducrId])

2. Rank by Date

Rank = RANKX (ALL('Table'), CALCULATE ( MAX ( ( 'Table'[Date]) ) ),,ASC,Dense)

3. First flag measure , and apply it to filter pane, set as "is 1"

First = IF(MAX('Table'[ProducrId]) in ALLSELECTED(ForSlicer[ProducrId]),[Rank],BLANK()) 

Eyelyn9_1-1640832820202.png

4. Second flag measure, and apply it to filter pane, set as "is 1" as well

Second = 
var _allCustomers=SUMMARIZE(FILTER(ALL('Table'),[First]=1),[CustomerID])
return IF(MAX('Table'[CustomerID]) in  _allCustomers && [Rank]=2,1,0)

 

Outputs:

Eyelyn9_2-1640832913797.png

Eyelyn9_3-1640832987394.png

 

Best Regards,
Eyelyn Qin
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

8 REPLIES 8
v-eqin-msft
Community Support
Community Support

Hi @jmukhtar ,

 

I have created a data sample,

Eyelyn9_0-1640832565524.png

According to this requirement: we are looking for a list of customers who have bought a specific product in first order and then use that list to see what these customers have bought in second order

 

Please follow these steps:

1. Create a productId table for slicer

ForSlicer = VALUES('Table'[ProducrId])

2. Rank by Date

Rank = RANKX (ALL('Table'), CALCULATE ( MAX ( ( 'Table'[Date]) ) ),,ASC,Dense)

3. First flag measure , and apply it to filter pane, set as "is 1"

First = IF(MAX('Table'[ProducrId]) in ALLSELECTED(ForSlicer[ProducrId]),[Rank],BLANK()) 

Eyelyn9_1-1640832820202.png

4. Second flag measure, and apply it to filter pane, set as "is 1" as well

Second = 
var _allCustomers=SUMMARIZE(FILTER(ALL('Table'),[First]=1),[CustomerID])
return IF(MAX('Table'[CustomerID]) in  _allCustomers && [Rank]=2,1,0)

 

Outputs:

Eyelyn9_2-1640832913797.png

Eyelyn9_3-1640832987394.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

PaulOlding
Solution Sage
Solution Sage

Hi @jmukhtar 

 

Here's an option for this.  It requires you to import a second copy of your products table that is disconnected from the rest of your model

PaulOlding_0-1640640137140.png

Then you can have a Second Order Amount measure like this:

Second Order Amount = 
VAR _Customers =
CALCULATETABLE(
    VALUES('Table'[customer_id]),
    'Table'[sort_order] = 1
)
VAR _Result = 
CALCULATE(
    SUM('Table'[net_sales]),
    'Table'[sort_order] = 2,
    _Customers,
    TREATAS(VALUES('Products 2'[product_name]),'Products'[product_name])
)
RETURN
    _Result

 

Finally, you'd use the product name from Products 2 table in your visual, along with the above measure.

PaulOlding_2-1640640502450.png

 

 

 

askhanduja
Helper I
Helper I

It would be helpful if you can attach a Power BI file with some sample data and screenshot of the desired output based on that sample data

Sample data is shared along with the requirements. I couldn't get it working on Power BI so far 😞 

ValtteriN
Super User
Super User

Hi,

In that case you can add this table:

ValtteriN_0-1640600508132.png


Then you can use that in a table to get the list of customers who bought e.g. Product C in first order:

ValtteriN_5-1640601097951.png


(add this to table visual ^^)

ValtteriN_1-1640600605862.png

OrderTypeFilter = IF(
OR(HASONEVALUE('Order Type'[Order Type])=FALSE(),
MAX('Order Type'[Order Type])=FirstOrder[FirstOrder]),1,0)

Now edit interactions to disable product filter from second visual:

 

ValtteriN_2-1640600730513.png
Filter second visual with "second"
ValtteriN_3-1640600777541.png

 


And as a result we notice that customers A and B bought product C in the first order. Out of these customers A bought product D in second order.

Data matches this:

ValtteriN_4-1640600840379.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @ValtteriN 

 

This solution gives us the first vs the second purchase, but What we want to get in second order visual is only the customers who have purchased from the selected category in first order. Please see the snapshot 

 

Screenshot 2021-12-27 at 21.56.18.png

 

1,3,6,8,9,10 customers bought product A in first order; and these customers bought product B, C and D in second order.

 

In second visual we want to see products bought by customers who have bought product A in first order

ValtteriN
Super User
Super User

Hi,

Here is one way to do this:

Start data:

ValtteriN_0-1640592380414.png


Dax (measure):

FirstOrder =
var Fdate = calculate(FIRSTDATE(FirstOrder[Date]),all(FirstOrder),FirstOrder[Customer]=max(FirstOrder[Customer]))
var Sdate = CALCULATE(FIRSTDATE(FirstOrder[Date]),all(FirstOrder),FirstOrder[Date]>Fdate,FirstOrder[Customer]=max(FirstOrder[Customer]))
var Cdate = MAX(FirstOrder[Date])
return

switch(true(),
 
Cdate=Fdate,"First Order",
Cdate=Sdate,"Second Order",
"Other")
End result:
Note that you need to use filter similar to the one in the picture to get the desired output.
ValtteriN_1-1640592432373.png

 

I hope this helps and if it does consider accepting this as a solution and giving the post a thumbs up!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @ValtteriN 

 

This doesn't work for us as we are looking for a list of customers who have bought a specific product in first order and then use that list to see what these customers have bought in second order

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.

Top Solution Authors