Forum Discussion

ilTac's avatar
ilTac
Frequent Visitor
5 years ago
Solved

SUM based on specific condition

Hello everyone,  i've been trying on this for a while and it seems i'm not able to do it. I think it should be simple but anyway:   here's my database: I would like to see % of good pieces...
  • thedatahiker's avatar
    5 years ago

    I tested this solution and it worked for my sample data set

    Pieces Below Company Target :=
     
    Var BelowTarget =
    CALCULATE(
    CALCULATE(sum(DataTest[Pieces]), FILTER(DataTest, [% Good Pieces] < [Target])),
    all(DataTest)
    )
    RETURN

    IF( [% Good Pieces] < [Target], BelowTarget)

    Pieces Above Company Target :=
    Var AboveTarget =
    CALCULATE(
    CALCULATE(sum(DataTest[Pieces]), FILTER(DataTest, [% Good Pieces] > [Target])),
    all(DataTest)
    )
    RETURN

    IF( [% Good Pieces] > [Target], AboveTarget)

     

  • ilTac's avatar
    ilTac
    5 years ago

    thedatahiker 

    yes!

    I just needed to add the filter in the Variable too.

     

     

    Thank you for your support!