Forum Discussion

JeanMariePBI's avatar
JeanMariePBI
Icon for Helper I rankHelper I
4 years ago
Solved

Calculated Column - cumulative sum using filter and ranked column

Hello,  I'm arelatively new to PBI and I need to create a calculated column that accumulates Net Sales based on the Products Price ranking (note multiple products appear in prod column).   The desired result is in the last column:

Product NumberProd Ranked by PriceNet PriceNet Sales(EXPECTED RESULT) Cumulative Revenue
Cat 1 $       7.00 $       7.00 $                       7.00
Cat 2 $       6.00 $       6.00 $                    13.00
Cat 3 $       5.00 $       5.00 $                    18.00
Cat 4 $       4.00 $       4.00 $                    22.00
Dog1 $       3.00 $       3.00 $                       3.00
Dog2 $       1.00 $       1.00 $                       4.00

 

 

My current DAX logic just returns the net sales value at each ranking and does not aggregate the sales.   Any help would be greatly appreciated.  Thank you!

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi JeanMariePBI ,

     

    You could use ALLEXCEPT() funtion and EARLIER() function. Check the formula.

    Column =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Product Number] ),
            'Table'[Prod Ranked by Price] <= EARLIER ( 'Table'[Prod Ranked by Price] )
        )
    )
    

     

     

    Best Regards,

    Jay

2 Replies

  • Hi JeanMariePBI ,

     

    Try the following code:

    Cumulative =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        ALL ( 'Table' ),
        'Table'[Product Number] = EARLIER ( 'Table'[Product Number] )
            && 'Table'[Prod Ranked by Price]
                <= EARLIER ( 'Table'[Prod Ranked by Price] )
    )
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi JeanMariePBI ,

     

    You could use ALLEXCEPT() funtion and EARLIER() function. Check the formula.

    Column =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Product Number] ),
            'Table'[Prod Ranked by Price] <= EARLIER ( 'Table'[Prod Ranked by Price] )
        )
    )
    

     

     

    Best Regards,

    Jay