Return a value in table based on the date within a range from a second table

chrisrick1

New Member
Joined
May 26, 2015
Messages
3
I have two tables, the first [TableData] is used to show the how much energy has been used on a given date, and the second [TableCharges] is used to show what the rate is per kWh.
[TableData] has multiple columns, but the relevant ones are [Date]; [Usage]; and [Rate]. [TableCharges] has three columns [StartDate]; [EndDate]; [Rate].

For each row, I want the cell under [TableData[Rate]] to return the [TableCharges[Rate]] where the the lookup value is [TableData[Date]] and it is looking for a match where the [TableData[Date]]>=[TableData[StartDate]] AND [TableData[Date]]<=[TableData[EndDate]].

Ideally I would like to resolve this using a excel formula instead of VBA if possible.

Any help would be appreciated.

Thanks
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi

Mappe2
B
4Rate
564,19
Tabelle1
Cell Formulas
RangeFormula
B5B5=XLOOKUP([@Date],TableCharges[StartDate],TableCharges[Rate],,1,1)
 
Upvote 0
Thanks for your response but I've tried getting xlookup to work and not had any success.
This is the [TableData]
1711038027779.png


This is [TableCharges[Rate]]
1711038127396.png


date format is dd/mm/yyyy

I was the Charging Rate should be 0.291666667 but as you can see the formula returns 0.41666667

Thanks
 
Upvote 0
I have managed to figure this out using adapting a formula posted in a different thread...

=IFERROR(INDEX(TableCharges[Rate],AGGREGATE(15,6,(ROW(TableCharges[Rate])-ROW(TableCharges[#Headers]))/((TableCharges[Start Date]<=[@[Month Ending]])*(TableCharges[End Date]>=[@[Month Ending]])),1)),"Not found")

The solution came from here. Lookup value within range

Thankyou to every one how has looked at this for me.
Cheers
 
Upvote 0
Solution
Just change the second to last 1 to -1.

Excel Formula:
=XLOOKUP([@Date],TableCharges[StartDate],TableCharges[Rate],,-1,1)
 
Upvote 0
@chrisrick1
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,109
Members
453,021
Latest member
Justyna P

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