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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

@ 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!:
The Definitive Guide to Power Query (M)

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

@ 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!:
The Definitive Guide to Power Query (M)

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

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

This is it!! Thank you so so so much

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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