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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

calculated column based on values in other row

I got a sales table with different types of sales.

I got a “reservation” and the “actual” sales.

 

Table looks like this:

Customer, OrderID, Sales, Sales Type, Item

A, 123, 100, “Reservation”, D

A, 123, 25, “Sales”, D

A, 234, 43, “Sales”, D

 

Customer can make a reservation amount which they can buy.

Sales can be a part of a reservation, but can also be a non related sale.

The relation is in the OrderID. If there is a “Reservation” with the same orderID as sales, then the sales is part of the “reservation”.

 

I want to mark the second row as part of a “Reservation”. (calculated column)

I want to know how much of a reservation is left (In this case 100-25 = 75)

 

Your help is much appreciated

1 ACCEPTED SOLUTION
Nathaniel_C
Community Champion
Community Champion

Hi @Anonymous 

I created two columns, but you can do it in one. Sometimes easier to understand in two and debug.

So, logic just get the value and if it is sales, make it negative.

Then sum all based on customer and order id. See table and visual.


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel

 

 

If pos/neg = var Reservation = IF(ORD[Sales Type] = "Reservation",ORD[Sales],ORD[Sales]*-1)


return Reservation

Left over = CALCULATE(SUM(ORD[If pos/neg]),FILTER(ALLEXCEPT(ORD,ORD[Customer],ORD[Order Id]),max(ORD[If pos/neg])))

ord.PNG

 

 

ord1.PNG

 





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

Proud to be a Super User!




View solution in original post

2 REPLIES 2
Nathaniel_C
Community Champion
Community Champion

Hi @Anonymous 

I created two columns, but you can do it in one. Sometimes easier to understand in two and debug.

So, logic just get the value and if it is sales, make it negative.

Then sum all based on customer and order id. See table and visual.


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel

 

 

If pos/neg = var Reservation = IF(ORD[Sales Type] = "Reservation",ORD[Sales],ORD[Sales]*-1)


return Reservation

Left over = CALCULATE(SUM(ORD[If pos/neg]),FILTER(ALLEXCEPT(ORD,ORD[Customer],ORD[Order Id]),max(ORD[If pos/neg])))

ord.PNG

 

 

ord1.PNG

 





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

Proud to be a Super User!




Anonymous
Not applicable

Thanks so much. This got me on the rigth track. 

With some small adjusments i got it to work.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.