Formula Required

Johnboy28

Board Regular
Joined
Jun 22, 2013
Messages
198
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2010
Platform
  1. Windows
Hi - Would appreciate an formula to calculate the "Days on Feed" - I have calculated the 1st answer. 368 Days

Processed Date minus sale date if Processed equal "Yes" AND if Processed equal "No" Sales date minus today's day AND if Processed equals "MORT" Processed Date minus Sale Date
Thank you


ProcessedProcessed DateSale DateDays on Feed
Yes4/10/20236/10/2024368
Yes4/10/20238/10/2024
No4/10/2023
No4/10/2023
MORT4/10/2023
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Assuming Processed is Column A and Row 1. This formula should work.
Excel Formula:
=SWITCH(TRUE,A2="Yes",C2-B2,A2="No",TODAY()-B2,A2="MORT",B2-C2,"")
 
Upvote 0
Perfect - Thank you very much.
If your data is not very large then you probably will not notice the difference but I would recommend against using SWITCH if possible. The reason is that SWITCH takes the time and resources to evaluate every test and every calculation in the formula even if the first one turns out to be the one needed.
For example for the formula above for row 2 of your sample data, Excel performs the following steps
  1. Tests to see if A2="Yes"
  2. Calculates C2-B2
  3. Tests to see if A2="No"
  4. Calculates TODA()-B2
  5. Tests to see if A2="MORT"
  6. Calculates B2-C2
  7. Stores "" in case none of the previous tests are True
  8. Now goes back and looks at the first test and finds that it is True so returns the value calculated at step 2
That is, steps 3 to 7 did not need to be done.

The following formula should return the same results
Excel Formula:
=IF(A2="Yes",C2-B2,IF(A2="No",TODAY()-B2,IF(A2="MORT",B2-C2,"")))

For this formula Excel performs the following steps
  1. Tests to see if A2="Yes", It is so
  2. Calculates and returns C2-B2 and stops
None of the other tests/calculations are performed. This is a more efficient approach & seems sensible to me.
 
Upvote 0
If your data is not very large then you probably will not notice the difference but I would recommend against using SWITCH if possible. The reason is that SWITCH takes the time and resources to evaluate every test and every calculation in the formula even if the first one turns out to be the one needed.
For example for the formula above for row 2 of your sample data, Excel performs the following steps
  1. Tests to see if A2="Yes"
  2. Calculates C2-B2
  3. Tests to see if A2="No"
  4. Calculates TODA()-B2
  5. Tests to see if A2="MORT"
  6. Calculates B2-C2
  7. Stores "" in case none of the previous tests are True
  8. Now goes back and looks at the first test and finds that it is True so returns the value calculated at step 2
That is, steps 3 to 7 did not need to be done.

The following formula should return the same results
Excel Formula:
=IF(A2="Yes",C2-B2,IF(A2="No",TODAY()-B2,IF(A2="MORT",B2-C2,"")))

For this formula Excel performs the following steps
  1. Tests to see if A2="Yes", It is so
  2. Calculates and returns C2-B2 and stops
None of the other tests/calculations are performed. This is a more efficient approach & seems sensible to me.
Thank you. Can also try this.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,620
Latest member
dsubash

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