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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! 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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.