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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

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

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.