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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.