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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Community Champion
Community Champion

@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!:
DAX For Humans

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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

This is it!! Thank you so so so much

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.