Index/Match, Nested IF statements, or Array Formula?

Ol Reliable

New Member
Joined
Dec 18, 2024
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Good evening, I'm at my wits end when trying to tackle the issue I'm having so lets start at the beginning with a little breakdown of my problem. Forgive me if I overshare.

TLDR:
I have 40 unique vehicle ID's in Column A formatted alongside a calendar with date headings. I am trying to compare Today to Yesterday for each vehicle that is in my possession to see if the number of maintenance actions increased or decreased. I need both of those totals as separate cells for end-of-month filing. It's not as simple as adding all my columns up and comparing to the previous day as my vehicles are constantly coming and leaving from the shop. I am only concerned about vehicles that are in my possession but if a vehicle leaves the shop on say, a Monday, and returns on the following Monday, I need to keep checking through all days that are N/A or BLANK until I find that number and do my comparison. Is this a lost cause? Am I doomed to doing mental gymnastics at the end of my very long days?

BACKGROUND:
- My agency blocks VBA so I cannot use visual basic to solve my problem so I'm restricted to formula based solutions.
- I have a master sheet that will be my front end display and I have additional sheets that I'm going to be hiding once the operations are working.
- My master sheet is a Calendar that I aptly named as such for clarity but it's not formatted as a typical calendar. It starts on the 27th of November in the C column and then will continue incrementally increasing every column ad infinitum.
- In the A column I have a list of 40 unique vehicle ID's I'm tracking for number of number of maintenance actions. This information should be irrelevant in this problem but I posted this information for clarity's sake.
- For each unique vehicle ID, I need to compare Today to Yesterday to see whether the amount of maintenance actions increased or decreased and total each respective to each other. For some instances where the vehicle wasn't in my possession yesterday, I need to keep looking back through that history until I find its last entry and compare that number to Today.
- I don't absolutely have to have a record of maintenance actions saved to this workbook but it is nice to have a one-stop-shop that I can review back on old data but I do need to have a record of maintenance actions that either increased and decreased for records keeping purposes. I based and built this current workbook off of memory from the old workbook that I had stored in a Teams folder that was deleted and unrecoverable so I am rebuilding this from scratch with additional features. I had to do these calculations by hand and it is very time consuming. I'm trying to work smarter than harder. Also, that old file didn't have these nice features.
- My 3 sheets are named as follows: Calendar, Calendar_Add, and Calendar_Sub. Both the _Add and _Sub would be hidden and are only placeholders for formulas. There are additional sheets in this workbook that do other things, mainly to help me log the daily maintenance actions.
- Below is an example of how the front end spread sheet is displayed. Column A is the Vehicle ID, that number will not change. I have 40 Vehicles I am tracking maintenance actions. N/A means that the vehicle is not in the shop so therefore, I don't have data on the vehicle until it returns to the shop.
- Weekends are blank because I don't want to come into the shop to collect that data, who likes working weekends? Not this guy.
- Lastly, in my project, the vehicle ID's start on cell A10. A1:A8 are reserved for additional information that I may need to add. A9 starts the Headers.

Veh ID27-Nov-2428-Nov-2429-Nov-2430-Nov-241-Dec-242-Dec-243-Dec-244-Dec-245-Dec-24
1400145638N/AN/A39383942
1500123420N/AN/A192018N/A
1510456728N/AN/A28N/AN/A29
16202123N/AN/AN/AN/AN/AN/AN/A
1630345630N/AN/A30293031
20101234N/AN/AN/AN/AN/AN/AN/A

- If the above rows are labeled A through J (etc...), I need to compare H2 to G2 for example and see if it increased or decreased and document how much. I need to do that to all cells that have maintenance data in it.

CURRENT DATA:
To make my current formula as "simple" as possible, I created two soon-to-be hidden sheets and I'm currently working on the Calendar_Add sheet which should take the current cell and compare it to the cell to its immediate left. It checks to see if it is greater, less or equal to. If it's equal to, it writes a 0. If it's less than, it will subtract THIS cell from THAT cell. If it's greater then, it writes a 0. I wrote the following which works for Tuesday through Friday, but Monday doesn't work properly.

Excel Formula:
=IF(Calendar!H10="N/A", "0",
IF(Calendar!H10>Calendar!G10, (Calendar!H10-Calendar!G10)),
IF(Calendar!H10=Calendar!G10, "0")
IF(AND(Calendar!G10="", Calendar!F10="", Calendar!H10>Calendar!E10), (Calendar!H10-Calendar!E10),
IF(AND(Calendar!G10="", Calendar!F10="", Calendar!H10=Calendar!E10), "0",
IF(AND(Calendar!G10="", Calendar!F10="", Calendar!H10<Calendar!E10), "0",
IF(AND(Calendar!G10="", Calendar!F10="", Calendar!E10="N/A", Calendar!H10>Calendar!D10), (Calendar!H10-Calendar!D10),
IF(AND(Calendar!G10="", Calendar!F10="", Calendar!E10="N/A", Calendar!H10=Calendar!D10), "0",
IF(AND(Calendar!G10="", Calendar!F10="", Calendar!E10="N/A", Calendar!H10<Calendar!D10), "0",
IF(AND(Calendar!G10="", Calendar!F10="", Calendar!E10="N/A", Calendar!D10="N/A", Calendar!H10>Calendar!C10), Calendar!H10-Calendar!C10),
IF(AND(Calendar!G10="", Calendar!F10="", Calendar!E10="N/A", Calendar!D10="N/A", Calendar!H10=Calendar!C10), "0",
IF(AND(Calendar!G10="", Calendar!F10="", Calendar!E10="N/A", Calendar!D10="N/A", Calendar!H10<Calendar!C10), "0", "0")))))))))

Let me break down my mental illness that is that code, bear in mind that it would be one continuous string of code but to save what little sanity I have left, I broke it apart for this example.
Line 1: If THIS cell(H10) is N/A, make it 0
Line 2: If THIS cell(H10) is GREATER than THAT cell(G10) then subtract G10 from H10
Line 3: If THIS cell is EQUAL to THAT cell, make it 0
Line 4: This is where I try to check for a weekend which would be all blank cells. If the left two cells are BLANK AND THIS cell(H10) is GREATER than the 3rd cell on the left (which should have a number in it) then do the math.
Line 5: Weekend check, compare THIS cell to what would be Friday, if they are EQUAL, make it 0
Line 6: The same as Line 5 but if they are LESS than, make it 0
Line 7: Weekend check and a Friday holiday check (N/A), follows basic math
Line 8: Weekend check and a Friday holiday check EQUAL, make it 0
Line 9: Weekend check and a Friday holiday check LESS than, make it 0
Line 10: Weekend check and a Friday & Thursday holiday check (N/A), follow basic math
Line 11: Weekend check and a Friday & Thursday holiday check, EQUAL, make it 0
Line 12: Weekend check and a Friday & Thursday holiday check, LESS than, make it 0, If FALSE make it 0

H10 was just where I was going to drop the formula then drag the little green box to automatically adjust the cell references so that cell reference shouldn't matter, at least I don't think so. I may be wrong.

With all that said, using the above formula on the example spreadsheet:
Veh ID27-Nov-2428-Nov-2429-Nov-2430-Nov-241-Dec-242-Dec-243-Dec-244-Dec-245-Dec-24
14001456#REF000039013
15001234#REF000019100
15104567#REF000028000
16202123000000000
16303456#REF000030011
20101234000000000

With this data, I can add up each column and pull that info over to the main Calendar sheet to show me how many added maintenance actions were to each vehicle. It's not so simple as just adding up all the cells in one column then comparing that to the sum of the column in front of it because it doesn't tell me exactly how many jobs were added due to the possibility that another vehicle's maintenance actions went down. My problem is that Monday isn't pooling through the weekend correctly nor can I determine if the check for N/A is working. The 27th of November breaks because that was the first day I started collecting this data so it has nothing in front of it to check and I don't want it to pull the vehicle ID into the formula and collect wrong data. I'm not married to using nested IF statements, if there's another less memory intensive way of solving this problem, I'm all ears. I thought maybe an INDEX MATCH function might work but I have no idea where to start, that or using an ArrayFormula or a Pivot Table for Pete's sake... I'm willing to try anything. If I don't have to use the extra sheets then sure. I'm at a loss.

Some potential pitfalls that could potentially happen during the daily collection of this data:
- What happens if all cells in a row are N/A?
- What happens when THAT cell is N/A when compared to THIS cell? Repeat checking left until I get a number to compare to.
Lastly, I have a conditional format for weekend dates: =IF(WEEKDAY(B9)>2, FALSE, TRUE) .... B9 is the first cell where the calendar starts.

It may not matter but I was going to total each column in this example to Row 6, and when I finish my Subtraction sheet, its data would get added to Row 7.

Well, that's that. Hopefully there's a much easier way of pulling and organizing this data that my simple mind cannot fathom. Please help me Excel Gurus.

-Ol' Reliable
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Welcome to the Forum!

For the data you've posted, what results do you want to show?

ABCDEFGHIJ
1Veh ID27-Nov-2428-Nov-2429-Nov-2430-Nov-241-Dec-242-Dec-243-Dec-244-Dec-245-Dec-24
21400145638N/AN/A39383942
31500123420N/AN/A192018N/A
41510456728N/AN/A28N/AN/A29
516202123N/AN/AN/AN/AN/AN/AN/A
61630345630N/AN/A30293031
720101234N/AN/AN/AN/AN/AN/AN/A
Sheet1
 
Upvote 0
Good Morning,

Thank you @StephenCrump for your assistance. I'm currently on my work computer so I cant upload files or use that L2BB application but I'll try to do my best to explain it here. Given that range of data in your post, I would expect to see the following numbers:

Added:NIL / Reference001125
Subtracted:NIL / Reference001220
Veh ID27-Nov-2428-Nov-2429-Nov-2430-Nov-241-Dec-242-Dec-243-Dec-244-Dec-245-Dec-24
1400145638N/AN/A39383942

The 'Added:' and 'Subtracted:' data is what I am looking for. B2:B7 is the first column in this case with no previous data so no calculation is possible on this range of cells. C2:C7 are all 'N/A' because no data was collected because of the long holiday weekend so the result would either be N/A Added & Subtracted or 0 in both cells. I'm using 0's in this case. Same with D2:D7. E & F is a weekend, no data collected. G2 begins looking left, sees a BLANK weekend, continues looking left, sees two N/A's. Continues looking left, sees 38 then compares B2 to G2. In this case, the number increased by 1 so we'll store that as a +1. Working down to G3, we look left until we find another number, in this case it's also B3. We compare the two, notice that it went down by one so we'll store it as -1. G4 & B4 are the same, so that's a 0. G5 is N/A so we'll store either nothing or a 0, whichever's easier. G6 to B6 is the same, so that's a 0 and G7 is N/A so that's a 0. Now at the top of G column, I add all of my +1's, in this case there's just 1 so only 1 new maintenance action was added. I do the same with the subtracted, there's only one -1 so only 1 maintenance action was complied with so I document a 1 in the subtracted Cell.

H2 looks left to G2, sees that it's less by one so we identify a -1. H3 sees G3 as an increase so this is +1. H4 is N/A so it's a 0. H5 is N/A so it's a 0. H6 is is less by one, so -1 is transcribed. H7 is N/A so 0. Column H added 1 job so I put a 1 in the Added box and this column went down by 2, so I put a 2 in the Subtracted box. This continues as we advance through the Columns. I currently have to do this calculation by hand so I was hoping to set up Excel to do it for me as it should be a "simple" comparison. Looking at the data, it isn't a simple Total up Column H and compare it's total to Column G and find the difference because our equipment varies whether or not it's in the shop or not so the data would be skewed.

At the end of the month, I'll total up all the Added numbers and total up all the Subtracted numbers for records keeping purposes and data analyzation. That's a simple SUM a range of cells formula.

With that said, looking at my OP, my disaster of a formula works on Tuesday through Friday's but on Monday's, it breaks. It ends up totaling up the entire column and I'm getting numbers in the 600's which is incorrect.

When I get home tonight, I'll try to see if I cant upload my spreadsheet to see if that will better assist us with finding a working solution but the meat and potatoes of the problem is in that example I posted. Not being allowed to use VBA really stinks. I would like to add that in some cases, there may be weeks of time where the cells for that row are N/A before the first number is found to compare against the reference cell. That would be a huge nested IF statement for that scenario which I would like to avoid.

Thanks again for your interest in my problem.

-Ol' Reliable
 
Upvote 0
Edit to add: I felt like it would be easiest to create two separate sheets where one sheet has a formula that calculates the jobs added and a separate sheet that calculates the jobs subtracted but that may be me overthinking possible solutions to my problem. Thanks again!

-Ol' Reliable
 
Upvote 0
This replicates your results:

ABCDEFGHIJ
1Veh ID27 Nov 202428 Nov 202429 Nov 202430 Nov 20241 Dec 20242 Dec 20243 Dec 20244 Dec 20245 Dec 2024
21400145638N/AN/A39383942
31500123420N/AN/A192018N/A
41510456728N/AN/A28N/AN/A29
516202123N/AN/AN/AN/AN/AN/AN/A
61630345630N/AN/A30293031
720101234N/AN/AN/AN/AN/AN/AN/A
8
914001456383838383839383942
1015001234202020202019201818
1115104567282828282828282829
1216202123000000000
1316303456303030303030293031
1420101234000000000
15
16Added00001125
17Subtracted00001220
Sheet1
Cell Formulas
RangeFormula
A9:A14A9=A2:A7
B9:B14B9=IF(B2:B7="N/A",0,B2:B7)
C9:J14C9=IF((C2:C7="N/A")+(C2:C7=""),B9:B14,C2:C7)
C16:J16C16=SUM((C9#>B9#)*(C9#-B9#))
C17:J17C17=SUM((C9#<B9#)*(B9#-C9#))
Dynamic array formulas.

If your first table is formula generated, rather than just values, you could build this into the one table -in essence, if the formula returns "N/A" because the vehicle is not in the workshop, or if it's a weekend/holiday, use the previous column value.
 
Upvote 1
Solution
This replicates your results:

ABCDEFGHIJ
1Veh ID27 Nov 202428 Nov 202429 Nov 202430 Nov 20241 Dec 20242 Dec 20243 Dec 20244 Dec 20245 Dec 2024
21400145638N/AN/A39383942
31500123420N/AN/A192018N/A
41510456728N/AN/A28N/AN/A29
516202123N/AN/AN/AN/AN/AN/AN/A
61630345630N/AN/A30293031
720101234N/AN/AN/AN/AN/AN/AN/A
8
914001456383838383839383942
1015001234202020202019201818
1115104567282828282828282829
1216202123000000000
1316303456303030303030293031
1420101234000000000
15
16Added00001125
17Subtracted00001220
Sheet1
Cell Formulas
RangeFormula
A9:A14A9=A2:A7
B9:B14B9=IF(B2:B7="N/A",0,B2:B7)
C9:J14C9=IF((C2:C7="N/A")+(C2:C7=""),B9:B14,C2:C7)
C16:J16C16=SUM((C9#>B9#)*(C9#-B9#))
C17:J17C17=SUM((C9#<B9#)*(B9#-C9#))
Dynamic array formulas.

If your first table is formula generated, rather than just values, you could build this into the one table -in essence, if the formula returns "N/A" because the vehicle is not in the workshop, or if it's a weekend/holiday, use the previous column value.

You are a life saver! I knew it had to be something simple but I didn't have as good of a grasp on dynamic array formulas. You solved my problem and it works perfectly. Now lets see if I understand exactly what's going on with your formulas so please correct me if I'm wrong.

Formula in A9 clones the master vehicle ID listing.
Formula in B9 is checking the first column in the master list and replacing all 'N/A's' in THIS clone list with 0's.
Formula in C9 is checking the second column in the master list for N/A's and BLANKS, if TRUE it's copying the cell data to the left in the clone list otherwise it is copying the current cell data from the master list.
Formulas in C16&C17 look simple enough but I'm not entirely sure what's going on exactly. The first parenthesis are checking to see if THIS cell is greater than the cell on the left but am I understanding correctly that you're multiplying TRUE against a basic subtraction formula? Or is this just saying that the subtraction will only happen if the first parenthesis is TRUE? Also, I'll have to look more into the '#' symbol. It looks like it takes the starting cell reference and spills downward until it runs out of data.

Again, you've shaved about an hour off my workday with that crazy simple solution. Thanks a ton! With that said, there is an issue with the formula. Earlier I mentioned that I wanted to try to put the formulas on another sheet that I could hide or protect. My main sheet is titled 'Calendar'. I copied it and renamed it to 'Calendar_Formula'. Working in the new sheet, I selected the range of cells that had all the tallied maintenance actions and cleared the data so I am working with just my Vehicle ID's and my Headers. Following your example, I input the following in the first cell in the first column, C10 in this case. (B10 is a hidden column):

Excel Formula:
=IF(Calendar!C10:Calendar!C49="N/A",0,Calendar!C10:Calendar!C49)

I was expecting this dynamic array to populate the column with cloned data from the 'Calendar' tab but the first cell is only displaying the formula as written above. It would be nice to have my formulas protected behind a hidden cell. Maybe I'm doing something wrong. You did solve my problem though so I will mark it as the solution.

-Ol' Reliable
 
Upvote 0
I was expecting this dynamic array to populate the column with cloned data from the 'Calendar' tab but the first cell is only displaying the formula as written above. It would be nice to have my formulas protected behind a hidden cell sheet. Maybe I'm doing something wrong. You did solve my problem though so I will mark it as the solution.
Strange, I can't edit my post, so I've corrected the quote.

-Ol' Reliable
 
Upvote 0
You have a limited time period - I think 10 minutes - to edit a post. Any corrections after that will need to be via separate post, as you have done.

If the formula, rather than the value(s), appear, it looks like you have the cell formatted as text. Format as numeric, use the F2 key to edit the formula and simply hit RETURN, and the results should now display?
 
Upvote 0
Formulas in C16&C17 look simple enough but I'm not entirely sure what's going on exactly. The first parenthesis are checking to see if THIS cell is greater than the cell on the left but am I understanding correctly that you're multiplying TRUE against a basic subtraction formula?

This might help illustrate? Two slightly different ways of getting the same result. if you use boolean TRUE/FALSE values in a formula, Excel coerces the TRUE/FALSE values to 1 and 0 respectively.

ABCDE
1Old valueNew valueDifferenceIncrease?
2121TRUE
3110FALSE
4231TRUE
530-3FALSE
6264TRUE
721-1FALSE
8
9Total increases6
106
Sheet1
Cell Formulas
RangeFormula
E2:E7E2=B2:B7>A2:A7
D2:D7D2=B2-A2
E9E9=SUM(IF(E2#,D2:D7,0))
E10E10=SUM(D2:D7*E2#)
Dynamic array formulas.
 
Upvote 0
This might help illustrate? Two slightly different ways of getting the same result. if you use boolean TRUE/FALSE values in a formula, Excel coerces the TRUE/FALSE values to 1 and 0 respectively.

ABCDE
1Old valueNew valueDifferenceIncrease?
2121TRUE
3110FALSE
4231TRUE
530-3FALSE
6264TRUE
721-1FALSE
8
9Total increases6
106
Sheet1
Cell Formulas
RangeFormula
E2:E7E2=B2:B7>A2:A7
D2:D7D2=B2-A2
E9E9=SUM(IF(E2#,D2:D7,0))
E10E10=SUM(D2:D7*E2#)
Dynamic array formulas.

That is a fantastic solution! I never would've thought of that. You're literally multiplying by either a 1 or 0 depending on the case. Now, one last question but I'm not sure of the protocol if I should post it here or open a new thread but we sometimes have a friendly competition in the workshop where we compare the the two teams on who made the best improvement during a time period. I would like to be able to filter the data based on color. One of my other sheets filters this data using the =SUBTOTAL() function. How would I use that formula to be able to run your original solution to use filtered data across two sheets? Bearing in mind that I don't believe the formula on the Calendar_Formula sheet is taking in account the filtered data on the main Calendar sheet. Is it as simple as:

Excel Formula:
=SUBTOTAL(9,(C9#>B9#)*(C9#-B9#))

I'm not sure if the filtered data is affecting the cloned dataset. Does that make sense? Thanks again, you've been a big help.

-Ol' Reliable
 
Upvote 0

Forum statistics

Threads
1,225,725
Messages
6,186,648
Members
453,367
Latest member
bookiiemonster

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