Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Incremental into cumulative

Hi

 

I have been trying solutions but i just don't get it

I want to do the following on Power BI

 

Like a sum with condition on date and on the the same product x lob

I tried TotalYTD but it didn't work.

Does someone knows how to do it ?

 

  • Hi, Anonymous 

    According to your description, I can roughly understand your requirement, you want to sum the "amount" if it's the same product and Lob for all valuation date anterior to the one in the line and create a slicer to filter the data based on the date column, right? I think you can create a measure to use the AllSelected() function instead of All() like this to achieve your requirement:

    Cumulative Amount 1 =
    
    CALCULATE(SUM('Table'[Amount]),FILTER(ALLSELECTED('Table'),[LoB]=MAX('Table'[LoB])&&[Valuation Date]<=MAX('Table'[Valuation Date])))
    
    

    And you can get what you want, like this:

     

    You can download my test pbix file below

    For more info about the Allselected() function in DAX, please refer to this link:

    https://docs.microsoft.com/en-us/dax/allselected-function-dax

     

    Thank you very much!

     

    Best Regards,

    Community Support Team _Robert Qin

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

5 Replies

  • smpa01's avatar
    smpa01
    Icon for Community Champion rankCommunity Champion

    Anonymous  you can use the following measure

     

    Measure =
    CALCULATE (
        SUM ( 'Table'[Amount] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Valuation Date] <= MAX ( 'Table'[Valuation Date] )
        ),
        KEEPFILTERS ( SUMMARIZE ( 'Table', 'Table'[Product], 'Table'[LoB] ) )
    )

     

     

     

    If you need calculated column

    cumulativeSum =
    SUMX (
        FILTER (
            'Table',
            'Table'[Product] = EARLIER ( 'Table'[Product] )
                && 'Table'[LoB] = EARLIER ( 'Table'[LoB] )
                && 'Table'[Valuation Date] <= EARLIER ( 'Table'[Valuation Date] )
        ),
        'Table'[Amount]
    )
    

     

     

     

     

     

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    Anonymous See if this helps: S Excel to DAX Translation - Microsoft Power BI Community

     

    Otherwise, Sorry, having trouble following, can you post sample data as text and expected output?
    Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

    Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

    The most important parts are:
    1. Sample data as text, use the table tool in the editing bar
    2. Expected output from sample data
    3. Explanation in words of how to get from 1. to 2.

    • Anonymous's avatar
      Anonymous
      Not applicable

      OK so i found this

       

      Cumulative Total =
      CALCULATE (
      SUM(Sheet1[Amount]),
      FILTER (
      ALL( Sheet1),
      Sheet1[Valuation Date] <= EARLIEST ( Sheet1[Valuation Date])))
       
      Which give me the cumulative sum by valuation date but i cannot add filter.
      Can someone help
  • Anonymous's avatar
    Anonymous
    Not applicable

    Thanks I'll have a look.

     

     

    The data is below. The output is col "Cumulative Amount 1"

    It sums "amount" if it's the same product and Lob for all valuation date anterior to the one in the line

     

    ProductLoBValuation DateAmountAmount 2MonthCumulative Amount 1
    AAccident01/01/202110100January10
    AAccident01/02/202120200February30
    AAccident01/03/202130300March60
    AAccident01/04/202140400April100
    AAccident01/05/202150500May150
    AAccident01/06/202160600June210
    AAccident01/07/202170700July280
    AAccident01/08/202180800August360
    AAccident01/09/202190900September450
    AAccident01/10/20211001000October550
    AMotor01/01/2021150250January150
    AMotor01/02/2021200300February350
    AMotor01/03/2021250350March600
    AMotor01/04/2021300400April900
    AMotor01/05/2021350450May1250
    AMotor01/06/2021400500June1650
    AMotor01/07/2021450550July2100
    AMotor01/08/2021500600August2600
    AMotor01/09/2021550650September3150
    AMotor01/10/2021600700October3750
  • v-robertq-msft's avatar
    v-robertq-msft
    Icon for Community Support rankCommunity Support

    Hi, Anonymous 

    According to your description, I can roughly understand your requirement, you want to sum the "amount" if it's the same product and Lob for all valuation date anterior to the one in the line and create a slicer to filter the data based on the date column, right? I think you can create a measure to use the AllSelected() function instead of All() like this to achieve your requirement:

    Cumulative Amount 1 =
    
    CALCULATE(SUM('Table'[Amount]),FILTER(ALLSELECTED('Table'),[LoB]=MAX('Table'[LoB])&&[Valuation Date]<=MAX('Table'[Valuation Date])))
    
    

    And you can get what you want, like this:

     

    You can download my test pbix file below

    For more info about the Allselected() function in DAX, please refer to this link:

    https://docs.microsoft.com/en-us/dax/allselected-function-dax

     

    Thank you very much!

     

    Best Regards,

    Community Support Team _Robert Qin

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.