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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jludwick
Frequent Visitor

Change DAX calculated column using EARLIER Function

Hello,

 

I recently read that you should not use the EARLIER function. I recently inherited a dataset file that uses this function and it keeps crashing, likely due to the EARLIER function. I am trying to convert this formula into the proper format using variables but I'm having some trouble. 

 

The current code is set up like so to get the cumulative balance as of the most recent invoice. How can I adjust this to remove the EARLIER function but get the same result?

 

_Balance Cumulative =
calculate(sum(Invoices[Balance]),
          ALLEXCEPT(Invoices,Invoices[Customer ID + Company Desc]),
          filter(
             all(Invoices[Invoice Date]),Invoices[Invoice Date] <= 
                 EARLIER(Invoices[Invoice Date])))

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @jludwick ,

 

If you want to create a calculated column, you can try:

_Balance Cumulative =
var _a=Invoices[Invoice Date]
return
calculate(sum(Invoices[Balance]),
          ALLEXCEPT(Invoices,Invoices[Customer ID + Company Desc]),
          filter(
             all(Invoices[Invoice Date]),Invoices[Invoice Date] <= _a
                 ))

If you want to create a measure, you can try:

 

_Balance Cumulative =
calculate(sum(Invoices[Balance]),
          ALLEXCEPT(Invoices,Invoices[Customer ID + Company Desc]),
          filter(
             all(Invoices[Invoice Date]),Invoices[Invoice Date] <= 
                 MAX(Invoices[Invoice Date])))

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

View solution in original post

2 REPLIES 2
ThxAlot
Super User
Super User

In a calculated column, it's highly recommended to use VAR to subsitute for EALIER/ERLIEST for better readability and maintainability,

_Balance Cumulative =
VAR __dt = Invoices[Invoice Date]
RETURN
    CALCULATE(
        SUM( Invoices[Balance] ),
        ALLEXCEPT( Invoices, Invoices[Customer ID + Company Desc] ),
        Invoices[Invoice Date] <= __dt
    )

 



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



Anonymous
Not applicable

Hi @jludwick ,

 

If you want to create a calculated column, you can try:

_Balance Cumulative =
var _a=Invoices[Invoice Date]
return
calculate(sum(Invoices[Balance]),
          ALLEXCEPT(Invoices,Invoices[Customer ID + Company Desc]),
          filter(
             all(Invoices[Invoice Date]),Invoices[Invoice Date] <= _a
                 ))

If you want to create a measure, you can try:

 

_Balance Cumulative =
calculate(sum(Invoices[Balance]),
          ALLEXCEPT(Invoices,Invoices[Customer ID + Company Desc]),
          filter(
             all(Invoices[Invoice Date]),Invoices[Invoice Date] <= 
                 MAX(Invoices[Invoice Date])))

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.