cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper V
Helper V

Acumulate field

Hi all,
I need to find the accumulated value of an operation. I have this table:

COUNTNAMEDATEHDBALANCE
52000028BANK131/12/2018      19.000,00-    19.000,00
  01/01/2019       1.640,00                    -  -    17.360,00
  01/02/2019       1.635,00                    -  -    15.725,00
  01/03/2019       1.630,00                    -  -    14.095,00
  01/04/2019       1.625,00                    -  -    12.470,00
  01/05/2019       1.620,00                    -  -    10.850,00
  01/06/2019       1.615,00                    -  -       9.235,00
  01/07/2019       1.610,00                    -  -       7.625,00
  01/08/2019       1.605,00                    -  -       6.020,00
  01/09/2019       1.600,00                    -  -       4.420,00
  01/10/2019       1.595,00                    -  -       2.825,00
  01/11/2019       1.590,00                    -  -       1.235,00
  01/12/2019      21.120,00-    22.355,00
  TOTAL     17.765,00     40.120,00-    22.355,00

 

and I want to find the column BALANCE that is equal to = Previous balance -D + H with the condition that if it is the first row of the group (COUNT) then it is equal to = -D + H. What is the DAX formula to get it?
Thank you.

 

3 REPLIES 3
Highlighted
Community Support
Community Support

Re: Acumulate field

hi, @Raul 

You could use EARLIER Function in this formula to add a new column'

Column = 
VAR _firstdate =
    CALCULATE (
        MIN ( 'Table'[DATE] ),
        FILTER (
            'Table',
            'Table'[COUNT] = EARLIER ( 'Table'[COUNT] )
                && 'Table'[NAME] = EARLIER ( 'Table'[NAME] )
        )
    )
RETURN
    IF (
        _firstdate = 'Table'[DATE],
        - 'Table'[D] + 'Table'[H],
        - CALCULATE (
            SUM ( 'Table'[D] ),
            FILTER (
                'Table',
                'Table'[DATE] = _firstdate
                    && 'Table'[COUNT] = EARLIER ( 'Table'[COUNT] )
                    && 'Table'[NAME] = EARLIER ( 'Table'[NAME] )
            )
        )
            + CALCULATE (
                SUM ( 'Table'[H] ),
                FILTER (
                    'Table',
                    'Table'[COUNT] = EARLIER ( 'Table'[COUNT] )
                        && 'Table'[NAME] = EARLIER ( 'Table'[NAME] )
                        && 'Table'[DATE] <= EARLIER ( 'Table'[DATE] )
                )
            ) - 'Table'[D]
    )

Result:

3.JPG

By the way: On 1/110/2019, it should be -4420-0+1695=-2725 not -2825

 

here is pbix file, please try it.

 

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Helper V
Helper V

Re: Acumulate field

Thank you very much for your help @v-lili6-msft,

I tried your new calculated column and I'll tell you if it worked for me.

Talk to you later.

Highlighted
Community Support
Community Support

Re: Acumulate field

hi, @Raul 

Could you please tell me if your problem has been solved? If it is, could you please mark the helpful replies as Answered?

 

Best Regards,

Lin

 

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

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

July 2020 Community Highlights

July 2020 Community Highlights

Learn about the exciting things that happened in July.

Featured Data Story of The Month

Featured Data Story of The Month

All Data Stories Gallery contributions are reviewed for each month. We select a contribution and feature the community member the following month.

Power BI Dev Camp - Developing with .NET Core

Power BI Dev Camp - Developing with .NET Core

Learn how to develop custom web applications for Power BI using .NET Core 3.1 and .NET 5.

Power BI Desktop August 2020 Update

Power BI Desktop August 2020 Update

We have great updates this month! Click the link for the video with more info.

Top Solution Authors
Top Kudoed Authors