Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Sum With Multiple Filters

here's an easier one...  or at least it should be, I've looked in previous posts but didn't see this situation addressed...  I am attempting to write a formula to sum column c in the below example, u...
  • Anonymous's avatar
    Anonymous
    7 years ago

    Hi Anonymous ,

    I do agree with you that it isn't elegant. Here is a solution that works :

     

    TOTAL = CALCULATE(SUMX('Table';'Table'[QTY AVAILABLE]/
    COUNTX ( FILTER ( 'Table'; EARLIER ( 'Table'[LOCATION] ) = 'Table'[LOCATION] ); 'Table'[LOCATION] ) );ALLEXCEPT('Table';'Table'[PN]))

     

    If you want to understand how it works, I described it below

     

    1. Find the number of occurences of each LOCATION 

    OCCURENCES = COUNTX ( FILTER ( 'Table'; EARLIER ( 'Table'[LOCATION] ) = 'Table'[LOCATION] ); 'Table'[LOCATION] )

    2. Divide QTY AVAILABLE by the number of occurences found 

    CalculatedQTY = 'Table'[QTY AVAILABLE]/'Table'[OCCURENCES]

    3. Sum this calculated occurences

    RESULT = CALCULATE( SUM( 'Table'[CalculatedQTY] ); ALLEXCEPT( 'Table'; 'Table'[PN] ))

    Tell me if it is any better for you,

     

    Regards, 

    Etienne