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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
jal1aaa
Frequent Visitor

Return the value for records that is the latest date less than a selected date

I have a data table that lists values of projects as they change over time.  The values are regularly updated and the database keeps all historical updates.  I have been able to create a measure to only select projects with the max create date to only display the latest project and summarize the totals based on the current date.  But I want to be able to select a date in a slicer and have the report return the latest values that are less than or equal to that date.  For example, i have two data tables:

A list of projects and all of their updates

Projects  
Project IDDate CreatedValue
Project A1/1/2024100
Project A1/19/2024125
Project A2/15/2024

95

Project A3/1/2024150
Project B12/1/202365
Project B1/10/2024100
Project B3/15/2024100

 

And a date table that has our forecast dates in it

Dates 
ForecastDate
Jan forecast1/31/2024
Feb Forecast2/28/2024
Mar Forecast3/31/2024

 

Using the data above as an example, I want to create a slicer with the dates and if the user selects the Feb Forecast, the values returned for Project A and B are the ones in red (the latest date prior to 2/28/2024)

 

Any suggestions?

2 ACCEPTED SOLUTIONS
ryan_mayu
Super User
Super User

@jal1aaa 

you can create a measure and add that measure to the visual filter

Measure =
VAR _date=maxx(FILTER(all('Projects'),'Projects'[Date Created]<=max(Dates[Date])&&Projects[Project ID]=max(Projects[Project ID])),'Projects'[Date Created])
return if(max('Projects'[Date Created])=_date,1,0)
 
11.PNG
 
pls see the attachment below
 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

v-zhouwen-msft
Community Support
Community Support

Hi @ryan_mayu ,thanks for the quick reply, I'll share my thought process.

Hi @jal1aaa ,

The Table data is shown below:

vzhouwenmsft_0-1714095690464.png

vzhouwenmsft_1-1714095713394.png

Please follow these steps:
1. Use the following DAX expression to create a measure

Measure = 
VAR _a = SELECTEDVALUE('Table2'[Date])
VAR _b = MAXX(FILTER('Table','Table'[Date Created] <= _a),'Table'[Date Created])
VAR _c = LOOKUPVALUE('Table'[Project ID],'Table'[Date Created],_b)
VAR _d = LOOKUPVALUE('Table'[Value],'Table'[Date Created],_b)
RETURN _c & " " & _b & " " & _d

2.Final output

vzhouwenmsft_2-1714095780601.png

vzhouwenmsft_3-1714095799418.png

vzhouwenmsft_4-1714095816333.png

 

 

View solution in original post

2 REPLIES 2
v-zhouwen-msft
Community Support
Community Support

Hi @ryan_mayu ,thanks for the quick reply, I'll share my thought process.

Hi @jal1aaa ,

The Table data is shown below:

vzhouwenmsft_0-1714095690464.png

vzhouwenmsft_1-1714095713394.png

Please follow these steps:
1. Use the following DAX expression to create a measure

Measure = 
VAR _a = SELECTEDVALUE('Table2'[Date])
VAR _b = MAXX(FILTER('Table','Table'[Date Created] <= _a),'Table'[Date Created])
VAR _c = LOOKUPVALUE('Table'[Project ID],'Table'[Date Created],_b)
VAR _d = LOOKUPVALUE('Table'[Value],'Table'[Date Created],_b)
RETURN _c & " " & _b & " " & _d

2.Final output

vzhouwenmsft_2-1714095780601.png

vzhouwenmsft_3-1714095799418.png

vzhouwenmsft_4-1714095816333.png

 

 

ryan_mayu
Super User
Super User

@jal1aaa 

you can create a measure and add that measure to the visual filter

Measure =
VAR _date=maxx(FILTER(all('Projects'),'Projects'[Date Created]<=max(Dates[Date])&&Projects[Project ID]=max(Projects[Project ID])),'Projects'[Date Created])
return if(max('Projects'[Date Created])=_date,1,0)
 
11.PNG
 
pls see the attachment below
 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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