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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
igaca
Helper III
Helper III

Strange EARLIER() result in Variance to Prev Row Value - Can anyone shed light on the result?

Am not understanding the last result...the -355.  Would have expected a return of 9.

Am also curious if someone can provide insight in how to modify the code to evaluate to BLANK() for the very first row given that there is no previous value to compare to and return a correct result?

 

Thanks!

 

Var to Prev DAX excerpt.png

2 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

 

This formula works

 

=if(ISBLANK(LOOKUPVALUE([Activs Cnt Col],Data[Data Date],CALCULATE(max([Data Date]),FILTER(Data,[Data Date]<EARLIER(Data[Data Date]))))),BLANK(),[Activs Cnt Col]-LOOKUPVALUE([Activs Cnt Col],Data[Data Date],CALCULATE(max([Data Date]),FILTER(Data,[Data Date]<EARLIER(Data[Data Date])))))

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

KHorseman
Community Champion
Community Champion

Your original version called for the max of [Activs Cnt Col] where the date was earlier than the current row. Look at all the values in that column on earlier dates. Of all the values on dates before 7/1, the max was 733 on either 4/30 or 5/3.

 

Perhaps you thought your formula would return the value of [Activs Cnt Col] where the date was the max before the current row? But that's not what your formula actually says.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

10 REPLIES 10
Ashish_Mathur
Super User
Super User

Hi,

 

This formula works

 

=if(ISBLANK(LOOKUPVALUE([Activs Cnt Col],Data[Data Date],CALCULATE(max([Data Date]),FILTER(Data,[Data Date]<EARLIER(Data[Data Date]))))),BLANK(),[Activs Cnt Col]-LOOKUPVALUE([Activs Cnt Col],Data[Data Date],CALCULATE(max([Data Date]),FILTER(Data,[Data Date]<EARLIER(Data[Data Date])))))

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

That works; thank you, sir.  Now, and more importantly, do you (or anyone else) have any insight as to why the behavior in the initial measure (returning a "-355" as opposed to a "9")?  

 

Also, let me make sure I understand your approach correctly:

 

1) you are using "CALCULATE(max([Data Date]),FILTER('Test Table',[Data Date]<EARLIER('Test Table'[Data Date]))" to return the previous context Data Date scalar value

 

2) This needs to be wrapped with conditional logic to account for the instance of there not being a previous / earlier value (as in the case of the earliest Data Date value).  In such a case we're returning a blank (ISBLANK())...

 

3) else we're subtracting the current row context [Activs Cnt Col] value from the previous one accessed using EARLIER()

 

Let me know any thoughts you may have in converting this approach to a measure in a most efficient way.

 

Thanks!

You are welcone.  Yes, your understanding is correct.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
KHorseman
Community Champion
Community Champion

Your original version called for the max of [Activs Cnt Col] where the date was earlier than the current row. Look at all the values in that column on earlier dates. Of all the values on dates before 7/1, the max was 733 on either 4/30 or 5/3.

 

Perhaps you thought your formula would return the value of [Activs Cnt Col] where the date was the max before the current row? But that's not what your formula actually says.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Ok, that was a silly one.   Thanks for straightening me out...clearly have been staring at a computer screen for entirely too long Smiley Very Happy

KHorseman
Community Champion
Community Champion

I did literally the exact same thing about three weeks ago.  Smiley LOL





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Ok, let's see if we can get the MEASURE to work right.  Here's my first, failed attempt:

 

Measure Pattern - DRAFT.png

Hi,

 

Share the file for this question.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

 

See below:

 

SData Measure Test

 

Thanks for taking the time/interest to help!

 

IG

Hi,

 

My solution will not work in a measure because the EARLIER function requires a row content which is only available in the Data model (not in the Pivot Table)


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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