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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Swilson2112
Frequent Visitor

Return a value from a table based on comparing two different fields in that same table..

I have this table: 

 

I want to compare the Invoice Date Column vs the Change Date Time Column and then return the Last Daily Change for the Change Date Time that has the closest before value.

 

In this example below:

Invoice Date:                                                               1/15/2021

Closest before Change Date and Time:                       6/14/19 15:17

Last Daily Change:                                                       .4495

 

I would like to create this as a DAX measure and insert the Last Daily Change Value into an existing visual on my dashboard that is showing Invoice#, Invoice date and some other sales information.

INVOICEINVOICE DATEPart #LINEFIELD_NAMEBEFOREAFTERDATE_CHGLast Daily ChangeChanged Date Time
225551/15/21100-1100Rate 0.4152/8/190.4152/8/19 11:09
225551/15/21100-1100Rate0.4150.492/13/190.492/13/19 6:27
225551/15/21100-1100Rate0.490.51952/27/190.51952/27/19 12:19
225551/15/21100-1100Rate0.51950.44956/14/190.44956/14/19 15:17
225551/15/21100-1100Rate0.44950.915/17/210.915/17/21 10:48
225551/15/21100-1100Rate0.911.129/22/211.129/22/21 16:30
225551/15/21100-1100Rate1.120.449512/3/211.1212/3/21 7:28
225551/15/21100-1100Rate0.44951.1212/3/211.1212/3/21 7:30
225551/15/21100-1100Rate1.120.449512/10/211.1212/10/21 6:53
225551/15/21100-1100Rate0.44950.9112/10/211.1212/10/21 7:10
225551/15/21100-1100Rate0.911.1212/10/211.1212/10/21 7:12
225551/15/21100-1100Rate1.120.9112/10/211.1212/10/21 7:18
225551/15/21100-1100Rate0.911.1212/10/211.1212/10/21 7:19
225551/15/21100-1100Rate1.120.43951/26/221.121/26/22 16:09
225551/15/21100-1100Rate0.43950.84551/26/221.121/26/22 16:42
225551/15/21100-1100Rate0.84550.911/26/221.121/26/22 16:43
225551/15/21100-1100Rate0.910.9651/26/221.121/26/22 16:44
225551/15/21100-1100Rate0.9651.021/26/221.121/26/22 16:45
225551/15/21100-1100Rate1.021.121/26/221.121/26/22 16:46
1 ACCEPTED SOLUTION
v-robertq-msft
Community Support
Community Support

Hi, 

According to your description, I can roughly understand your requirement, but based on the needs you said that you want to get the Last Daily Change for the Change Date Time that has the closest before value, I think the Changed date time should be 5/17/21 10:48 instead of the  6/14/19 15:17, right?

 

If you don’t have a problem, you can try this method to get the expected result:

You can create a calculated column like this:

Date diff =

abs(DATEDIFF('Table'[Changed Date Time],'Table'[INVOICE DATE],SECOND))

Then create a measure like this:

Flag =

var _mindiff=MINX(ALL('Table'),'Table'[Date diff])

return

IF(MAX('Table'[Date diff])=_mindiff,1,0)

 

And you can create a table chart to place the measure as the visual filter to get what you want, like this:

vrobertqmsft_0-1645429418786.png

 

You can download my test pbix file below

 

If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

1 REPLY 1
v-robertq-msft
Community Support
Community Support

Hi, 

According to your description, I can roughly understand your requirement, but based on the needs you said that you want to get the Last Daily Change for the Change Date Time that has the closest before value, I think the Changed date time should be 5/17/21 10:48 instead of the  6/14/19 15:17, right?

 

If you don’t have a problem, you can try this method to get the expected result:

You can create a calculated column like this:

Date diff =

abs(DATEDIFF('Table'[Changed Date Time],'Table'[INVOICE DATE],SECOND))

Then create a measure like this:

Flag =

var _mindiff=MINX(ALL('Table'),'Table'[Date diff])

return

IF(MAX('Table'[Date diff])=_mindiff,1,0)

 

And you can create a table chart to place the measure as the visual filter to get what you want, like this:

vrobertqmsft_0-1645429418786.png

 

You can download my test pbix file below

 

If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.