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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
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. 

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)


)



Helpful resources

Announcements
Users online (25)