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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Patrykrz
Frequent Visitor

Sum rows depending on a condition

Hello,

 

I am running a report in Power Bi (SQL data) where I have hunders of companies. The goal is to track if the discount is properly applied in the system. The discount applies  5% for 2 or more contracts, and 10% for more than 4 contracts. 

 

And life would be great if there were no exceptions. Two issues:

1) first one is that there are exceptions for the fleet discount eligibility. Lets say customer VIP is eligible for 5% even if they have 1 contract active and there wont be more contracts signed.

 

I have managed to overcome it with the formula:

if [Company ID]="454674" and [Number of contracts per Company name]=1 then "5%" else if [Number of contracts per Company name]>=4 then "10%" else if [Number of contracts per Company name]>=2 then "5%" else "0.00")

 

2) The second issue is that each company has individual ID, but we should sum up the number for contract for each divisions (Clothes ABC Mexico+Clothes ABC Texas; Shirts LLC+Shirts LLC Montana).

 

I have added the table below and in red you can see the desired column result. I would greatly appreciate your support.

 

 

Company IDCompany nameContract IDNumber of contracts per Company nameDiscount for 2 and more contracts (5%) for more than 4 (10%)
101102Clothes ABC Mexico44-4415%
103103Clothes ABC Texas99-9915%
103111Wool ABC88-8810%
104123Shirts LLC77-78410%
104123Shirts LLC77-77410%
104123Shirts LLC77-79410%
104123Shirts LLC77-71410%
121545Shirts LLC Montana56-87210%
121545Shirts LLC Montana56-89210%
121323Belts23-9125%
121323Belts23-9225%
454674VIP 33-8715%
2 REPLIES 2
Syndicate_Admin
Administrator
Administrator

Hi,

 

 This isn't really a solution as your data sounds quite variable (Customer names are always a pain!) but I'd suggest you need some additional fields within the DB or lookup tables creating within PQ (Exception Customers and Customer Groups).
I think once you have these applying a logic for which rate should be applied should be quite simple.

 

Hope that helps

That's what I did. Good suggestion. Thank you!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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