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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

August Carousel

Fabric Community Update - August 2024

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