Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Icon for Administrator rankAdministrator
5 years ago
Solved

Accumulated Balance

Hello

I'm trying to calculate a balance that gives me the summation of an account in a period,

The fields I have are the transid (seat number), the line_id (line number), what I'm looking for is to create a measure that calculates the accumulated balance line by line, that is, what marks the Acum column.

TransIdLine_IDAccountNivel4RefDateDebitCredit Balance Now
7297230000800300001/01/2020 0:001624.310,00 € 1.624,31 1.624,31
984330000800300031/01/2020 0:001624.310,00 € 1.624,31 3.248,62
73131030000800300031/01/2020 0:000,00 €0.45- 0,45 3.248,17
7313430000800300031/01/2020 0:000,00 €1.23- 1,23 3.246,94
7313630000800300031/01/2020 0:000,00 €1.36- 1,36 3.245,58
7313830000800300031/01/2020 0:000,00 €1.81- 1,81 3.243,77
7307030000800300031/01/2020 0:000,00 €1619.46- 1.619,46 1.624,31
5720130000800300014/02/2020 0:00913.320,00 € 913,32 2.537,63
5666130000800300024/02/2020 0:00475.20,00 € 475,20 3.012,83
8505530000800300029/02/2020 0:001309.670,00 € 1.309,67 4.322,50
8493930000800300029/02/2020 0:009.30,00 € 9,30 4.331,80

I've tried this formula but I've got all the same-day notes

Saldo_acum_ = CALCULATE(sum(Consulta1[valor]),FILTER(ALLSELECTED(Consulta1),Consulta1[RefDate]<=MAX(Consulta1[RefDate])))
Os agradecería algo de luz
Greetings.
  • Anonymous's avatar
    Anonymous
    5 years ago

    Don't @Syndicate_Admin,

    Because the date is not unique, you cannot use the Date column for accrual in the FILTER function. You must add an index column in Power Query.

    Before you add an index column, you must ensure that the date column is sorted from small to large and that the Balance column is also sorted from small to large, so that the result is as desired.

    18.png19.png20.png

    Tips: I cannot enter the PBIX file that you provided to add index columns in Power Query, so I exported the data and recreated a PBIX file.

    So the measure is

    Saldo_acum = CALCULATE(SUM('Sheet1'[Saldo]),FILTER(ALLEXCEPT('Sheet1',Sheet1[Account],Sheet1[BPLId]),[Index]<=MAX('Sheet1'[Index])))

    21.png

    You can check more details from here.

    Best regards

    Stephen Tao

    If this post helps,then consider Accepting it as the solution to help other members find it faster.

6 Replies

    • Syndicate_Admin's avatar
      Syndicate_Admin
      Icon for Administrator rankAdministrator

      Thank you for responding

      It's not exactly what I'm looking for.

      I'll explain

      I have a calculated column that is the value (debit-credit) - balance

      Here's the report

      JmSahuco_14-1613762895602.png


      As you can see there are several notes that are with the same Refdate '31/01/20', the same TransId 7313 and different Line_Id

      The column saldo_acum is the formula I've put up

      Saldo_acum_ = CALCULATE(sum(Consulta1[valor]),FILTER(ALLSELECTED(Consulta1),Consulta1[RefDate]<=MAX(Consulta1[RefDate])))

      What I want is that instead of joining by date, I make the cumulative line by line by transid and line_id

      This result is filtered by Account, so it has to be used for all filters

      Thanks a lot

      • stevedep's avatar
        stevedep
        Icon for Memorable Member rankMemorable Member

        Can you share a sample dataset with some scenarios and expected output?

    • Syndicate_Admin's avatar
      Syndicate_Admin
      Icon for Administrator rankAdministrator

      Hey.

      What if there is not only one booking per day per account? Does it consider the order in the table or do I have to insert an index and add that to the formular? If the last is correct, could you please tell me how you would solve it?!

  • Anonymous's avatar
    Anonymous
    Not applicable

    Don't @Syndicate_Admin,

    Because the date is not unique, you cannot use the Date column for accrual in the FILTER function. You must add an index column in Power Query.

    Before you add an index column, you must ensure that the date column is sorted from small to large and that the Balance column is also sorted from small to large, so that the result is as desired.

    18.png19.png20.png

    Tips: I cannot enter the PBIX file that you provided to add index columns in Power Query, so I exported the data and recreated a PBIX file.

    So the measure is

    Saldo_acum = CALCULATE(SUM('Sheet1'[Saldo]),FILTER(ALLEXCEPT('Sheet1',Sheet1[Account],Sheet1[BPLId]),[Index]<=MAX('Sheet1'[Index])))

    21.png

    You can check more details from here.

    Best regards

    Stephen Tao

    If this post helps,then consider Accepting it as the solution to help other members find it faster.