Forum Discussion

Patrykrz's avatar
Patrykrz
Frequent Visitor
3 years ago

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

  • 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

    • Patrykrz's avatar
      Patrykrz
      Frequent Visitor
      That's what I did. Good suggestion. Thank you!