cancel
Showing results for
Did you mean:
Highlighted
Regular Visitor

## nearest date match value

Hello,

I'm trying to create a column in which i want to compare two dates and if the two dates match, took the value from another column if the dates not exact match it gives the value of nearest date match.

need help

Regards,

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support

## Re: nearest date match value

Hi, @Akbera1

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

You may create a calculated column or a measure as below.

``````Calculated column:
Result Column =
IF(
[Date1]=[Date2],
[Another Date],
var _diff1 = ABS(TODAY()-[Date1])
var _diff2 = ABS(TODAY()-[Date2])
return
IF(
MIN(_diff1,_diff2)=_diff1,
[Date1],
[Date2]
)
)

Measure:
Result Measure =
var _date1 = SELECTEDVALUE('Table'[Date1])
var _date2 = SELECTEDVALUE('Table'[Date2])
return
IF(
_date1=_date2,
SELECTEDVALUE('Table'[Another Date]),
var _diff1 = ABS(TODAY()-_date1)
var _diff2 = ABS(TODAY()-_date2)
return
IF(
MIN(_diff1,_diff2)=_diff1,
_date1,
_date2
)
)``````

Result:

Best Regards

Allan

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

3 REPLIES 3
Highlighted
Super User VI

## Re: nearest date match value

Hi @Akbera1

try

``````Column =
var _d1 = today() - Table[Date1]
var _d2 = today() - Table[Date2]
RETURN
SWITCH(TRUE(),
_d1 = _d2, Table[Date3],
ABS(_d1) <= ABS(_d2), Table[Date1],
Table[Date2]
)``````

do not hesitate to give a kudo to useful posts and mark solutions as solution
Highlighted
Community Support

## Re: nearest date match value

Hi, @Akbera1

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

You may create a calculated column or a measure as below.

``````Calculated column:
Result Column =
IF(
[Date1]=[Date2],
[Another Date],
var _diff1 = ABS(TODAY()-[Date1])
var _diff2 = ABS(TODAY()-[Date2])
return
IF(
MIN(_diff1,_diff2)=_diff1,
[Date1],
[Date2]
)
)

Measure:
Result Measure =
var _date1 = SELECTEDVALUE('Table'[Date1])
var _date2 = SELECTEDVALUE('Table'[Date2])
return
IF(
_date1=_date2,
SELECTEDVALUE('Table'[Another Date]),
var _diff1 = ABS(TODAY()-_date1)
var _diff2 = ABS(TODAY()-_date2)
return
IF(
MIN(_diff1,_diff2)=_diff1,
_date1,
_date2
)
)``````

Result:

Best Regards

Allan

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Highlighted
Community Support

## Re: nearest date match value

Hi, @Akbera1

Best Regards

Allan

Announcements

#### Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

#### Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.

#### Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021