cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sv11 Regular Visitor
Regular Visitor

Previous day value

Hi,

 

I am trying to pull up the "DataPointValue" for the privious day (hoping to use this in a calculation).

 

Below is the snapshot of the data:

Capture.PNG

 

Current Formula used:

 

Previous row = CALCULATE
(MAX(Table[DataPointValue]),
TOPN(1, FILTER(ALLSELECTED(Table),
Table[AsOfDate] < MAX(Table[AsOfDate])),
Table[AsOfDate],
DESC
)
)
 
Problem:
 
When I try to select multiple "InstrumentDescription", the privous value is not getting calculated accurately. I need the calculation to dynamically group the data based on "InstrumentDescription" selection and pull up the privious value.
Also, is there a way to make the 1st record value for "Previous value" as 0?
 
I would greatly appreceate the help in solving this issue.
Thanks in advance.
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator v-yuezhe-msft
Moderator

Re: Previous day value

@sv11,

Is DataPointValue as existing field in your table? Please check my PBIX file.

Regards,
Lydia

Community Support Team _ Lydia Zhang
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

6 REPLIES 6
Super User IV
Super User IV

Re: Previous day value

I believe you want EARLIER like this:

 

Previous Row = 
VAR __previousDate = MAXX(FILTER(ALL('Table'),[AsOfDate] < EARLIER([AsOfDate])),[AsOfDate])
VAR __previous = MAXX(FILTER(ALL('Table'),[AsOfDate] = __previousDate),[DataPointValue])
RETURN
__previous

See my article on Mean Time Before Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...


I have book! Learn Power BI from Packt


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

Proud to be a Datanaut!

sv11 Regular Visitor
Regular Visitor

Re: Previous day value

@Greg_Deckler,

 

Thank you for yor response. I have tried cleating a column based on your suggested script. The values do not seem to be matching.

Capture2.PNG

There are multiple "InstrumentDescription"'s for each date and I guess the calculation is is not grouping the data for each "InstrumentDescription" and pulling in the respective previous value.

 

What do you suggest?

Thanks a ton for your help.

Moderator v-yuezhe-msft
Moderator

Re: Previous day value

@sv11,

Please change your DAX to the following:

Previous Row = 
VAR __previousDate = MAXX(FILTER(ALL('Table'),[AsOfDate] < EARLIER([AsOfDate])&&'Table'[InstrumentDescription]=EARLIER('Table'[InstrumentDescription])),[AsOfDate])
VAR __previous = MAXX(FILTER(ALL('Table'),[AsOfDate] = __previousDate),[DataPointValue])
RETURN
IF(ISBLANK(__previous),0,__previous)



Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
sv11 Regular Visitor
Regular Visitor

Re: Previous day value

@v-yuezhe-msft,

 

Thank you for your response and insight on DAX.

 

I have made changes to DAX as suggested, but I am still having trouble in pulling in the correct Previous value. 

This did solve part of my requirement (Starting with 0). 

 

Please find the snapshot below:

Capture3.PNG

Ideally, the highlighted values should be the same.

 

Here is the DAX code I used:

 

Previous row1 =
VAR _PreviousDate = MAXX(FILTER(ALL(Table), Table[AsOfDate] < EARLIER(Table[AsOfDate]) && Table[InstrumentDescription] = EARLIER(Table[InstrumentDescription])), Table[AsOfDate])
VAR _Previous = MAXX(FILTER(ALL(Table), Table[AsOfDate] = _PreviousDate), Table[DataPointValue])
RETURN
IF(ISBLANK(_Previous), 0, _Previous)
 
I really appreceate your help.
 
Thanks

 

Highlighted
Moderator v-yuezhe-msft
Moderator

Re: Previous day value

@sv11,

Is DataPointValue as existing field in your table? Please check my PBIX file.

Regards,
Lydia

Community Support Team _ Lydia Zhang
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

sv11 Regular Visitor
Regular Visitor

Re: Previous day value

Thanks Lydia. This really helps.

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

January 2020 Community Highlights

January 2020 Community Highlights

Make sure you didn't miss any of the things that happened in the community in January!

Top Solution Authors