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

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

 

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

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

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

 

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

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.

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