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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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!:
The Definitive Guide to Power Query (M)

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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