Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
KW123
Helper V
Helper V

Total from Prev Month carrying over into next month

Hi, 

I have this DAX:

VAR _customer = [AccountNbr]
VAR _date = [DisbDate]
VAR _table =
FILTER(
Disb,
Disb[AccountNbr] = _customer
&&Disb[DisbDate] < _date
)
VAR _lastdate =
MAXX( _table, Disb[DisbDate])
VAR _lasttransaction =
MAXX(
FILTER(
_table,
Disb[DisbDate]=_lastdate
),
Disb[Disbamt]
)
RETURN
[DisbAmt] - _lasttransaction

Essentially it is calculating the difference between rows for customer transactions.  

I have run into a small problem.  The last total for the previous month is carrying over into the next month and I need it to not do that.  

For example, in January, on the 31st, the final total is $1000.  On Feb 1st the total should be $10 but it is showing $1010 instead.  The same is happening for March.  

How do I fix the above DAX so that the balance from the last day of the previous month does not carry over to the first day of the next month? I have a separate Dates table too.  But when it will not allow me to replace Disb[DisbDate] with Dates[Date] 

Thank you! 
1 ACCEPTED SOLUTION

@KW123 Missed a )

Column =
  VAR _customer = [AccountNbr]
  VAR _date = [DisbDate]
  VAR _year = YEAR(_date)
  VAR _month = MONTH(_date)
  VAR _table =
    FILTER(
      Disb,
      Disb[AccountNbr] = _customer && Disb[DisbDate] < _date && YEAR([DisbDate]) = _year && MONTH([DisbDate]) = _month
    )
VAR _lastdate =
MAXX( _table, Disb[DisbDate])
VAR _lasttransaction =
MAXX(
FILTER(
_table,
Disb[DisbDate]=_lastdate
),
Disb[Disbamt]
)
RETURN
[DisbAmt] - _lasttransaction


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@KW123 Maybe:

Column =
  VAR _customer = [AccountNbr]
  VAR _date = [DisbDate]
  VAR _year = YEAR(_date)
  VAR _month = MONTH(_date)
  VAR _table =
    FILTER(
      Disb,
      Disb[AccountNbr] = _customer && Disb[DisbDate] < _date && YEAR([DisbDate]) = _year && MONTH([DisbDate] = _month
    )
VAR _lastdate =
MAXX( _table, Disb[DisbDate])
VAR _lasttransaction =
MAXX(
FILTER(
_table,
Disb[DisbDate]=_lastdate
),
Disb[Disbamt]
)
RETURN
[DisbAmt] - _lasttransaction


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

Thank you so much for your reply!! 
This is what I get if I copy and paste... 
NewDAX.png

@KW123 Missed a )

Column =
  VAR _customer = [AccountNbr]
  VAR _date = [DisbDate]
  VAR _year = YEAR(_date)
  VAR _month = MONTH(_date)
  VAR _table =
    FILTER(
      Disb,
      Disb[AccountNbr] = _customer && Disb[DisbDate] < _date && YEAR([DisbDate]) = _year && MONTH([DisbDate]) = _month
    )
VAR _lastdate =
MAXX( _table, Disb[DisbDate])
VAR _lasttransaction =
MAXX(
FILTER(
_table,
Disb[DisbDate]=_lastdate
),
Disb[Disbamt]
)
RETURN
[DisbAmt] - _lasttransaction


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

This is it!! Thank you so so so much

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.