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
DateValue
01.01.2019100
28.01.2019101
27.02.2019102
30.03.2019103

<tbody>
</tbody>


TblCAl
DateMonthValue
01.01.2019Jan
02.01.2019Jan
03.01.2019Jan
04.01.2019Jan
01.02.2019Feb
01.03.2019Mar
01.04.2019Mai

<tbody>
</tbody>


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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
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,213,534
Messages
6,114,186
Members
448,554
Latest member
Gleisner2

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