Forum Discussion

frankhofmans's avatar
frankhofmans
Helper IV
3 years ago
Solved

How identify change vs previous row?

hi all,

 

i have a customer database which logs all contract changes. Fe:

 

Start_DateEnd_DateCustomer IDSales price product ASales price product BSales price product Cfee %Change in sales price product B?
1-jan-2231-jan-22A00110012015010%No
1-feb-2231-mrt-22A00110015015010%Yes
1-apr-2230-jun-22A00111016016010%Yes
1-jul-22 A00111016017012%No
1-jan-2231-jan-22A00211012516011%No
1-feb-22 A00211512516012%No
1-jan-22 A00311212315011%No
1-jan-2231-jan-22A00410010511015%No
1-feb-2230-jun-22A00411010511515%No
1-jul-22 A00411011011515%Yes
1-jan-2231-jul-22A00514014012512%No
1-aug-22 A00514015015012%Yes
1-jan-2231-jul-22A00614014517015%No
1-aug-22 A00615014517016%No

 

i want to create a extra column (change in sales price product B). When the price of product B (for the same customers) changes, it's a Yes, otherwise a No.

 

Does anyone has a solution for this?

 

Many thanks,

Regards, Frank

 

  • Hi frankhofmans 

     

    You can create a new column with this DAX formula

    Change in product B? = 
    VAR _previousStartDate = MAXX(FILTER('Table','Table'[Start_Date]<EARLIER('Table'[Start_Date]) && 'Table'[Customer ID]=EARLIER('Table'[Customer ID])),'Table'[Start_Date])
    VAR _previousPrice = MAXX(FILTER('Table','Table'[Customer ID]=EARLIER('Table'[Customer ID]) && 'Table'[Start_Date] = _previousStartDate),'Table'[Sales price product B])
    RETURN
    IF(_previousPrice=BLANK(),"No",IF(_previousPrice='Table'[Sales price product B],"No","Yes"))

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.

1 Reply

  • v-jingzhang's avatar
    v-jingzhang
    Community Support

    Hi frankhofmans 

     

    You can create a new column with this DAX formula

    Change in product B? = 
    VAR _previousStartDate = MAXX(FILTER('Table','Table'[Start_Date]<EARLIER('Table'[Start_Date]) && 'Table'[Customer ID]=EARLIER('Table'[Customer ID])),'Table'[Start_Date])
    VAR _previousPrice = MAXX(FILTER('Table','Table'[Customer ID]=EARLIER('Table'[Customer ID]) && 'Table'[Start_Date] = _previousStartDate),'Table'[Sales price product B])
    RETURN
    IF(_previousPrice=BLANK(),"No",IF(_previousPrice='Table'[Sales price product B],"No","Yes"))

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.