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
nh27
Helper III
Helper III

Calculate discount using two tables

Hi fellow BI users, I need your help!


I am trying to create a measure called Discount which takes the discount value from a table "Discount_Lookup" and applies it to the row in "ZSALES" table.

 

There is a Many to One relationship right now from ZSALES to Discount_Lookup.

 

1.PNG

 

Discount = SUM(Zsales[Subtotal1])*SUM(Discount_Lookup[Discount])

 

The formula right now is taking SUM of total discount and applying that, but I want it row by row.

 

2.png

 

Total sum of discount is 0.82 which is what discount it is applying, but for above I want it row by row only. E.g. row 1 should be 2% of £28,224 and Discount column should be £564.48

 

Tried a few formula but hit a dead end, any ideas?

 

Thanks in advance 🙂

1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

HI @nh27 

 

Can you share a sample of your data (both tables)?

BTW, try this:

 

Discount = SUM(Zsales[Subtotal1])*MAX(Discount_Lookup[Discount])

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!!

 

View solution in original post

4 REPLIES 4
VahidDM
Super User
Super User

HI @nh27 

 

Can you share a sample of your data (both tables)?

BTW, try this:

 

Discount = SUM(Zsales[Subtotal1])*MAX(Discount_Lookup[Discount])

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!!

 

Thank you so much, this seems to have done the trick! I'm confused as to how MAX has resolved this, would you be kind enough to explain why this worked?

Thanks in advance

It seems there are many rows for each item in your table and those rows have 2% in the discount column, when you use SUM, it will return the sum of the 2% (if there are 10 rows that will return 20%), but MAX will return just one of them which is 2%.

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!!

YukiK
Impactful Individual
Impactful Individual

Use SUMX() instead of SUM(). Your measure will look like something like this:

 

Discount = SUMX(Zsales, Zsales[Subtotal1])*RELATED(Discount_Lookup[Discount]))

 

Please give it a thumbs up if this helps!

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.