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

Getting previous values from a dataset

Hello all,

 

I have a dataset Valuations consisting of market values per ValDate (I only have one business day per month) and per transaction ID as in the example below.

 

I need to have in my Power BI dashboard a table which gives me the values of each ID on one selected date (hich I get from a date slicer) and the date corresponding to the previous quarter (for example, in my dataset, the -3m date from 29-01-2021 would be 30-10-2020 and so on).

 

I tried calculating the second date using a measure which returns the correct date:

 

prevQuarter =
VAR date_t = SELECTEDVALUE('Valuations'[ValDate])
VAR date_t_1 = CALCULATE(MAX(Valuations[ValDate]), Valuations[ValDate]<date_t)
VAR date_t_2 = CALCULATE(MAX(Valuations[ValDate]), Valuations[ValDate]<date_t_1)
 
RETURN
CALCULATE(
     MAX(Valuations[ValDate]),
     Valuations[ValDate]<date_t_2)
)

 

However, I am not able to calculate a measure which returns the market value per ID at prevQuarter. I tried the following without success:

Value (prev quarter)=
CALCULATE (
     SUM(Valuations[Value]),
     FILTER(__dates, __dates[ValDate] = [prevQuarter])
)

 

Any idea of what I might be doing wrong?

 

ValDateIDValue
30-12-20201100
30-12-2020256
30-12-20203789
29-01-20211123
29-01-2021275
29-01-202131015
...  
1 ACCEPTED SOLUTION
amitchandak
Super User IV
Super User IV

@NunoSDCoelho , With help from a date table, try a measure like

 

trailing QTR = CALCULATE(SUM(Table[Value]),dateadd('Date'[Date],-1,QUARTER))



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

View solution in original post

4 REPLIES 4
amitchandak
Super User IV
Super User IV

@NunoSDCoelho , With help from a date table, try a measure like

 

trailing QTR = CALCULATE(SUM(Table[Value]),dateadd('Date'[Date],-1,QUARTER))



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

View solution in original post

Thanks @amitchandak for the suggestion.

 

However, that does not seem to solve the problem as my dates do not always correspond to the last day of the month.

 

I created a table with the unique values of my dates and added a new column to test your idea but I do not always get a date for the previous quarter:
PrevQuarter = DATEADD(dates[ValDate],-1,QUARTER)

 

Val Date     PrevQuarter

31-07-2020     30-04-2020

31-08-2020

30-09-2020     30-06-2020

30-10-2020

30-11-2020

30-12-2020     30-09-2020

29-01-2021

@NunoSDCoelho , You have to create a date table with all dates. 

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

I was not able to get your solution to work, probably because I am comparing different days within the quarters (eg, the 29 jan date would be compared to 30 nov).

 

I got what I wanted by creating a new column in my original dataset which gets the last date in the previous quarter (using PREVIOUSQUARTER() ) and then adding a new column which looks up this date in the values column (using LOOKUPVALUE() ). Does not seem to be the most efficient solution but at least it works..

Thanks for the help!

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

April Update

Check it Out!

Click here to read more about the April 2021 Updates!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

secondImage

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.