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
Anonymous
Not applicable

First discount received

Hi, I have a table with thousands of sales orders. I want a new column which calculates the amount of discount a customer received on their first order (ensuring first order status equals "processing" or "completed"). Below is a sample of the table (which has many more columns but I have reduced it to illustrate the problem).  

 

Adam_Jama_2-1632761873079.png

 

 

 

1 ACCEPTED SOLUTION

Hi,

Write these calculated column formulas

First created date = CALCULATE(MIN(Data[date_created]),FILTER(Data,Data[Unique ID]=EARLIER(Data[Unique ID])&&(Data[Order Status]="Completed"||Data[Order Status]="Processing")))
First discount received = LOOKUPVALUE(Data[discount_total],[date_created],[First created date],[Unique ID],[Unique ID],[Order Status],"Completed")

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

14 REPLIES 14
parry2k
Super User
Super User

@Anonymous maybe tweak it like this:

 

first discount = 
CALCULATE ( 
    SUM ( Sheet1[discount_total] ),
    (
        TOPN ( 
            1, 
            FILTER ( 
                ALLEXCEPT ( Sheet1, Sheet1[Unique ID] ), 
                Sheet1[Order Status] IN { "Completed", "Processing" } 
            ),  
            MIN (  Sheet1[date_created] ), 
            ASC 
        )
    )
)

 

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.

Anonymous
Not applicable

Thanks but it doesn't seem to work. There is an error 'A circulancy dependency was detected'

Anonymous
Not applicable

Thanks, I'll give it a try

parry2k
Super User
Super User

@Anonymous add this measure:

 

first discount = 
CALCULATE ( 

    SUM ( Sheet1[discount_total] ),
    (
        TOPN ( 1, ALLEXCEPT ( Sheet1, Sheet1[Unique ID] ),  ( MIN (  Sheet1[date_created] ) ), ASC )
    )
)

 

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.

Anonymous
Not applicable

Thanks, appreciate it. It appears to be missing the filter for order status (Completed or processing)?

 

parry2k
Super User
Super User

@Anonymous what is a customer in that file? I don't see a customer column? Also, it is good to explain the expected output.



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.

Anonymous
Not applicable

Unique ID is the customer ID. This is a full list of sales, For each row I would like to see the amount of discount that customer received for their first order. For wider context, It is apart of a churn model I am putting together, I am trying to see how long customers stay depending on the level of discount they received when they initially joined. 

parry2k
Super User
Super User

@Anonymous share using One drive/google drive.

 

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.

Anonymous
Not applicable

Hi,

Write these calculated column formulas

First created date = CALCULATE(MIN(Data[date_created]),FILTER(Data,Data[Unique ID]=EARLIER(Data[Unique ID])&&(Data[Order Status]="Completed"||Data[Order Status]="Processing")))
First discount received = LOOKUPVALUE(Data[discount_total],[date_created],[First created date],[Unique ID],[Unique ID],[Order Status],"Completed")

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Thanks, this works!!!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
jaideepnema
Solution Sage
Solution Sage

Hi @Anonymous ,
can you please share the dataset here ? It wouldn't be possible to get it from the image ?

Anonymous
Not applicable

I may be missing something but I can't seem to attach a file. 

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.