find nearest date

joslaz

Board Regular
Joined
May 24, 2018
Messages
76
Hello everyone,

I am looking for a Lookup-function in PowerPivot/ Dax to get the nearest date for a specific date.

I have the following two tables:

TblVal
[TABLE="width: 500"]
<tbody>[TR]
[TD]Date[/TD]
[TD]Value[/TD]
[/TR]
[TR]
[TD]01.01.2019[/TD]
[TD]100[/TD]
[/TR]
[TR]
[TD]28.01.2019[/TD]
[TD]101[/TD]
[/TR]
[TR]
[TD]27.02.2019[/TD]
[TD]102[/TD]
[/TR]
[TR]
[TD]30.03.2019[/TD]
[TD]103[/TD]
[/TR]
</tbody>[/TABLE]


TblCAl
[TABLE="width: 500"]
<tbody>[TR]
[TD]Date[/TD]
[TD]Month[/TD]
[TD]Value[/TD]
[/TR]
[TR]
[TD]01.01.2019[/TD]
[TD]Jan[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]02.01.2019[/TD]
[TD]Jan[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]03.01.2019[/TD]
[TD]Jan[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]04.01.2019[/TD]
[TD]Jan[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]01.02.2019[/TD]
[TD]Feb[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]01.03.2019[/TD]
[TD]Mar[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]01.04.2019[/TD]
[TD]Mai[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


The objective/ challange is to get for each date (tblCal) the respective value from the tblVal.
So the 01.01.2019 should get the value 100.

So every date between 01.01.2019 and 28.01.2019 should get the value 100.

Does anyone know how to manage this?



Best Regards
Joshua
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi,

try a calculated column on Tblcal with this:
=
VAR mydate =
CALCULATE (MIN ( Tblval[Date] ); FILTER ( CALCULATETABLE ( VALUES ( Tblval ) ); Tblval[Date] >= Tblcal[Date]))
RETURN
CALCULATE (MIN ( Tblval[Value] ); FILTER ( CALCULATETABLE ( VALUES ( Tblval ) ); Tblval[Date]= mydate ))
 
Upvote 0
Hey jorismoerings!
Thanks for your approach!

Is there maybe a sintax issue with RETURN? I put the function into the column in powerpivot. Is that right?
 
Upvote 0
Hi @joslaz

No, there's no issue but perhaps you've broken the formula into 2 calculated fields.
If so, that's not the case, you need to copy the entire string as 1 formula into the calculated field and not in 2 separate fields
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top