cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Regular Visitor

dax formula help

Hello,

 

I have a table with the following data: Account, year, month, euros. Each record has the total of money that has entered or exited an account in that month. Something like that:

 

Account   Year    Month  Euros 

5200        2017         1       800

5200        2017         2     -100

5200        2017         3       500

5200        2017         4   - 1800

524          2017         1       100

524          2017         2      -300

524         2017         3      -200

524         2017         4       500


I want to add a column that also tells me the balance. That is ... the balance to January 2017, is the sum of all fields "euros" from the beginning to the registration that has month 1, year 2017, for a certain account. In February, it is the same sum adding the record that has month 2, year 2017. Something like this:

 

Account   Year    Month  Euros   Balance

5200       2017         1       800         800

5200       2017         2     -100          700 

5200       2017         3       500       1200

5200       2017         4   - 1800       -600 

524         2017         1       100         100

524         2017         2      -300       -200

524         2017         3      -200       -400

524         2017         4       500       100



I've tried solving it in several ways with CALCULATE, but I do not give the solution. Any ideas?

 

1 ACCEPTED SOLUTION

Hi @RuZaGo,

 

Please create a calculated column below: 

 

Balance = CALCULATE(SUM(Table1[Euros]),FILTER('Table1','Table1'[Account]=EARLIER(Table1[Account]) && 'Table1'[Month]<=EARLIER(Table1[Month])))

 

p1.PNG

 

Best Regards,
Qiuyun Yu 

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

View solution in original post

4 REPLIES 4
Super User IV
Super User IV

Maybe something like:

 

Balance = CALCULATE( SUM([Euros]), FILTER(Table, [Month] <= EARLIER([Month]))

You could also play around with the Running Total quick measure. 


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Regular Visitor

Hello,

 

I have a table with the following data: Account, year, month, euros. Each record has the total of money that has entered or exited an account in that month. Something like that:

 

Account   Year    Month  Euros 

5200        2017         1       800

5200        2017         2     -100

5200        2017         3       500

5200        2017         4   - 1800

524          2017         1       100

524          2017         2      -300

524         2017         3      -200

524         2017         4       500


I want to add a column that also tells me the balance. That is ... the balance to January 2017, is the sum of all fields "euros" from the beginning to the registration that has month 1, year 2017, for a certain account. In February, it is the same sum adding the record that has month 2, year 2017. Something like this:

 

Account   Year    Month  Euros   Balance

5200       2017         1       800         800

5200       2017         2     -100          700 

5200       2017         3       500       1200

5200       2017         4   - 1800       -600 

524         2017         1       100         100

524         2017         2      -300       -200

524         2017         3      -200       -400

524         2017         4       500       100



I've tried solving it in several ways with CALCULATE, but I do not find the solution. Any ideas?

 

Hi @RuZaGo,

 

Please create a calculated column below: 

 

Balance = CALCULATE(SUM(Table1[Euros]),FILTER('Table1','Table1'[Account]=EARLIER(Table1[Account]) && 'Table1'[Month]<=EARLIER(Table1[Month])))

 

p1.PNG

 

Best Regards,
Qiuyun Yu 

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

View solution in original post

It works! Thank you very much

Helpful resources

Announcements
secondImage

Congratulations!

We are excited to announce the Power BI Super Users!

Wave Release 2

Check out the updates in Power BI.

Overview of Power BI 2020 release wave 2!

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors