简体   繁体   中英

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.

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)))

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM