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
crln-blue
Post Patron
Post Patron

Calculated Column that checks the previous row

Hello everyone, I'm trying to check the data of the previous row so I can compare it to the current row and apply some logic. I'm aware of the EARLIER and EARLIEST functions but somehow, it doesn't work as I expected them too. I wrapped them in a FILTER inside a CALCULATE function but it still doen't seem to work.

 

Below is my sample data:

Order IDOrder Item IDQty
100021000132
100021000232
100036000210
100044000128
100044000228
100044000328
100044000428
100044000528
100100000149
100100000249
1002220003108
100223000187
100223001087
100270000110
100272000116


Below is my expected result:

Order IDOrder Item IDQtyCalculated Col_Qty
10002100073232
100021000932 
10003600021010
10004400012828
100044000228 
100044000328 
100044000428 
100044000528 
10010000034949
100100000549 
1002220003108108
10022300058787
100223001087 
10027000011010
10027200011616

 

I can't really depend on the Order Item ID because sometimes, it doesn't start with "0001".

My goal is to check if the current data row of Order ID is the same with the previous row. If it is the same, set the Qty value as blank. If they are not the same, retain the Qty value.

 

Thank you!

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

Hi @crln-blue ,

 

First create an index column and count the number of occurrences of each Order ID.

Index = RANKX(FILTER(ALL('Order'), 'Order'[Order ID] = EARLIER('Order'[Order ID])), 'Order'[Order Item ID],, ASC, Dense)

 

Create a calculated column that sets the Qty value to blank if index is not equal to 1. If index = 1, Qty value is retained.

Calculated Col_Qty = IF('Order'[Index] = 1,'Order'[Qty],BLANK())

 

Drag columns to the report page for display.

vhuijieymsft_0-1710296206367.png

 

pbix file is attached.

 

If you have any further questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

View solution in original post

1 REPLY 1
v-huijiey-msft
Community Support
Community Support

Hi @crln-blue ,

 

First create an index column and count the number of occurrences of each Order ID.

Index = RANKX(FILTER(ALL('Order'), 'Order'[Order ID] = EARLIER('Order'[Order ID])), 'Order'[Order Item ID],, ASC, Dense)

 

Create a calculated column that sets the Qty value to blank if index is not equal to 1. If index = 1, Qty value is retained.

Calculated Col_Qty = IF('Order'[Index] = 1,'Order'[Qty],BLANK())

 

Drag columns to the report page for display.

vhuijieymsft_0-1710296206367.png

 

pbix file is attached.

 

If you have any further questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

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.