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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
fugazzetta
Frequent Visitor

Tag rows where a value appears both negative and positive.

So basically i have a sample data similar to this:

Invoice IDTypeWeightDestination
1Invoice10F
2Credit note-10F
3Invoice10D


Where I have a list of invoices with different details and values (this is just an mock up example, can't post the real table). Sometimes due to a mistake while completing an invoice they have to cancell the invoice creating a credit note. See example: first row is the created invoice with destination F, but the correct destination was D, so they first create a credit note that cancells the invoice, and then they create an invoice with the correct destination. Notice how the credit note has a negative numeric value to indicate it's cancelling the other one. 

My question is, how can I create a custom column using M in Power query that flags the first two rows where one value is positive and the next one is negative? This is the output i would like to have:

Invoice IDTypeWeightDestinationDelete_Flag
1Invoice10FY
2Credit note-10FY
3Invoice10D 


Also the reason for cancelling an invoice is not always due to destination being incorrectly completed, it could be some other field. But the weight value will always be negative if it is cancelling a previous invoice. Also the invoice ID is a random generated combination of numbers and letters, for the example I used just one number for simplicity, but it's not as easy as  comparing the number of the ID. 

My idea was to first create a custom column in M code like this:


Delete_1= if weight<0 then "Y" else ""

Then I wanted to compare the first row that has the same absolute value as the flagged rows where Delete_1="Y", and flag both rows based on that. But i  have no idea how to do that 😞 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @fugazzetta ,

 

You could use group by feature.

Calculate the sum of Weight group by Destination.

And if the sum value is 0, then "Yes".

 

Best Regards,

Jay

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @fugazzetta ,

 

You could use group by feature.

Calculate the sum of Weight group by Destination.

And if the sum value is 0, then "Yes".

 

Best Regards,

Jay

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors