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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Moody_Data
Frequent Visitor

Calculated Column based on Multiple Rows

Hello All,

 

I am looking to create what I think is a fairly simple calculated column that will calculate the 'Order Revenue' column below. 

 

The unique order number may contain multiple rows.  The order revenue column should be calculated only on the highest priced unit within that order.  Here is how the table is organized in Power BI:

 
Order NumberUnitPriceOrder Revenue
123Case20
123Pallet1010
456Case22
789Case20
789Pallet1010
    
 

I am looking to create the 'Order Revenue' column in red above.  If there is an order with multiple different units, the new column will display just the max value of the price.

 

Thank you in advance and please let me know if further explanation is needed.

 

1 ACCEPTED SOLUTION
V-pazhen-msft
Community Support
Community Support

@Moody_Data 

You could just drag ordernumber and price into the table visual, and use maximum categorize for price. max values.JPG

 

If you want to have the exact output in calculated column, the idea is you would need to create a index column, and if the order number for current row = previous role, then blank, if they are not the same order number you can return MAX(price) for the order number. Something like: 

Column = var maxprice = CALCULATE(MAX('Table'[Price]),FILTER('Table','Table'[Order Number]=EARLIER('Table'[Order Number]))) Return if([Order Number]= CALCULATE(MAX('Table'[Order Number]),FILTER('Table','Table'[Index]=EARLIER('Table'[Index])-1)),BLANK(),maxprice) 

 

Paul Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

4 REPLIES 4
V-pazhen-msft
Community Support
Community Support

@Moody_Data 

You could just drag ordernumber and price into the table visual, and use maximum categorize for price. max values.JPG

 

If you want to have the exact output in calculated column, the idea is you would need to create a index column, and if the order number for current row = previous role, then blank, if they are not the same order number you can return MAX(price) for the order number. Something like: 

Column = var maxprice = CALCULATE(MAX('Table'[Price]),FILTER('Table','Table'[Order Number]=EARLIER('Table'[Order Number]))) Return if([Order Number]= CALCULATE(MAX('Table'[Order Number]),FILTER('Table','Table'[Index]=EARLIER('Table'[Index])-1)),BLANK(),maxprice) 

 

Paul Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Thank you @V-pazhen-msft , I created the new index column and with the expression provided in the solution, the Order Revenue column now displays only the max price for those orders that contain multiple lines.

 

Much appreciated!

amitchandak
Super User
Super User

@Moody_Data , Create a new column like

Order Revenue = if([Price]= maxx(filter(Table, Table[Order Number] =earlier(Table[Order Number])),Table[Price]),[Price],blank())

@amitchandak , Many thanks for the response.

 

This is very close to working but I may have left out a scenario from the original post.

 

If there is an order that contains multiple rows of only the same item, it is returning the max value of both rows:

 

Order NumberUnitPriceOrder Revenue
987Case22
987Case22

 

Ideally would appear as the below so that each order is assigned only 1 price each:

 

Order Number UnitPriceOrder Revenue
987Case20
987Case22

 

I will also take a look - thank you for any ideas on how to modify this to just show 1 price per order.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.