VSR
VSR

Reputation: 97

How to calculate the value of a column based on another column values in Excel?

I have a table in which I have the Following columns.

        Date        XValue
    2018-07-16 
    2018-07-15
    2018-07-14   

Now the value of XValue depends on another table which has the following columns.

Day   XValue
Day1   0.1
Day2   0.2
Day3   0.4

This table contains value till Day 30.

So, based on the date, if yesterday was 15 July, It should take the Day 1 value 0.1 as the X value. Similarly, 14 July should take Day 2 value and so on till Day 30. Any day after 30 should take value as integer 1. Can anyone suggest, how can I implement this in Excel? I have tried conditional statements but nothing seems to work. Any help will be appreciated.

Upvotes: 0

Views: 58

Answers (1)

BigBen
BigBen

Reputation: 49998

You can simply take the difference of TODAY() and each of the dates, and look up the corresponding value (VLOOKUP or INDEX/MATCH or however you prefer).

With the "Date" table starting in A1 and the "Day" table starting in D1, this formula should work. If the date in question is today, the formula returns a blank string.

=IF(TODAY()-A2<1,"",IF(TODAY()-A2>30,1,VLOOKUP("Day" &TODAY()-A2,$D$1:$E$31,2,0)))

enter image description here

Upvotes: 1

Related Questions