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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
aJ2
Helper I
Helper I

Calculating ratios of multiple items in an order and then calculate discount

Hi.

 

I have table where I have id and order_id where id is the serial number. 

An order_id can have multiple items.

An order can have a discount amount with it ie at checkout, the person uses a discount code. 

I need to calculate the discount for each item in that particular order.

 

eg:- there are 3 items in an order, item A has a value 100, item B 200 and item C 300 respectively. A coupon code is used and the coupon value is 120. So the ratio between the 3 items are taken ie the ratio is 1:2:3. 

The equation becomes 1x+2x+3x= 120. => 6x=120 => x=20.

So the discount for item A is 20, Item B 40 and item C 60.

 

qkjfb'.PNG

 

 

Above is the snippet of sample data.

 

Kindly help.

 

1 ACCEPTED SOLUTION
Floriankx
Solution Sage
Solution Sage

Hello,

 

so you have a separate table with order_id and discount?

 

If you relate your order_id columns this does the job as Calculated column:

=VAR OrderID=[order_id]
VAR whole_order=CALCULATE(SUM(Table[cost]);FILTER(Table;Table[order_id]=OrderID))
RETURN Table[cost]/whole_order*RELATED(Discount[discount])

View solution in original post

2 REPLIES 2
Floriankx
Solution Sage
Solution Sage

Hello,

 

so you have a separate table with order_id and discount?

 

If you relate your order_id columns this does the job as Calculated column:

=VAR OrderID=[order_id]
VAR whole_order=CALCULATE(SUM(Table[cost]);FILTER(Table;Table[order_id]=OrderID))
RETURN Table[cost]/whole_order*RELATED(Discount[discount])

Yes. I had a separate table for discount and order_id. But then there was another table where an order_id was associated with a voucher code. 
So I used RELATED() and got the details for the coupon codes and then carried out the calculations.

 

Thank you so much for your help.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.