cancel
Showing results for
Did you mean:
Highlighted
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!

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Super User IV

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

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])))))`

Regards,
Ashish Mathur
http://www.ashishmathur.com
Highlighted
Super User I

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

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.

Proud to be a Super User!

10 REPLIES 10
Highlighted
Super User IV

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

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])))))`

Regards,
Ashish Mathur
http://www.ashishmathur.com
Highlighted
Helper III

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

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!

Highlighted
Super User I

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

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.

Proud to be a Super User!

Highlighted
Helper III

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

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

Highlighted
Super User I

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

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

Proud to be a Super User!

Highlighted
Helper III

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

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

Highlighted
Super User IV

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

You are welcone.  Yes, your understanding is correct.

Regards,
Ashish Mathur
http://www.ashishmathur.com
Highlighted
Super User IV

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

Hi,

Share the file for this question.

Regards,
Ashish Mathur
http://www.ashishmathur.com
Highlighted
Helper III

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

See below:

SData Measure Test

Thanks for taking the time/interest to help!

IG

Announcements

#### August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

#### July 2020 Community Highlights

Learn about the exciting things that happened in July.

#### Featured Data Story of The Month

All Data Stories Gallery contributions are reviewed for each month. We select a contribution and feature the community member the following month.

#### Power BI Dev Camp - Developing with .NET Core

Learn how to develop custom web applications for Power BI using .NET Core 3.1 and .NET 5.