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
sv11
Helper I
Helper I

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

@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
Greg_Deckler
Super User
Super User

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


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

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

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

@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

 

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

Thanks Lydia. This really helps.

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.