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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Akbera1
Frequent 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,

Syed Muhammad Akber

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @Akbera1 

 

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

Table:

h1.png

 

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:

e4.png

 

Best Regards

Allan

 

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

View solution in original post

3 REPLIES 3
v-alq-msft
Community Support
Community Support

Hi, @Akbera1 

 

Could you please show us some sample data and expected result with One Drive for Business? Do mask sensitive data before uploading. Thanks.

 

Best Regards

Allan

v-alq-msft
Community Support
Community Support

Hi, @Akbera1 

 

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

Table:

h1.png

 

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:

e4.png

 

Best Regards

Allan

 

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

az38
Community Champion
Community Champion

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
LinkedIn

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.