Excel Match function with concatenated value - excel-formula

I am somewhat new to writing large, complicated formulas with excel. I took over a report from someone about 7 months ago and it seems that every week I find issues with what was written with his formulas.
This week I am having issues with a match formula. We have a report we run for a big hardware store and they report based on weeks. This last week was 201501 (2015, week 1.) Last week was 201452 (2014, week 52.)
To look at 4 week sales averages, my predecessor setup 4 numbers that would change every week based on the week you type in one of the column headings. So, when I type 201452,
#1 is 201449
#2 is 201450
#3 is 201451
#4 is 201452
He feeds those into a match function.
I found this week that 201501 does not correctly display the weeks. I got
Results Formula Used
201501 =D1 (The cell where you type the Store's week)
201500 =IF(M1=201301,201252,IF(M1=201401,201352,M1-1))
201499 =IF(L1=201301,201252,IF(L1=201401,201352,L1-1))
201498 =IF(K1=201301,201252,IF(K1=201401,201352,K1-1))
I changed those formulas
Results New Formula
201501 =D1
201452 =IF(RIGHT(M1,2) = "01",(LEFT(M1,4) - 1)&"52",M1-1)
201451 =IF(RIGHT(L1,2) = "01",(LEFT(L1,4) - 1)&"52",L1-1)
201450 =IF(RIGHT(K1,2) = "01",(LEFT(K1,4) - 1)&"52",K1-1)
However, the match formulas he has setup throughout the workbook have not been fixed. They are still displaying "#N/A." One such formula is
=INDEX(N5:DZ5,1,MATCH(Data!$L$1,$N$1:$ED$1,0))
This formula basically looks at the column headers, and if it sees that the column header matches the week I've typed, will display the value within that range.
Basically, any formula that's being fed the 201452 value is returning "#N/A". The other numbers miraculously display data.
I've already tried converting all of my data in the affected rows to "General" format type. I've tried checking to see if I have spaces before or after in all of my formulas and column headers, but am still having no luck.
Any ideas?

After trying and trying and trying, I found that Excel does not like the concatenation. Trim does not help, Text does not help, Concatenate of course did not work.
I ended up realizing I could simply write
=IF(RIGHT(M1,2) = "01",M1-49,M1-1)
This makes it so that in the instance where the number to the right of it is the first week, subtract 49 days and produce 52 instead of 00.

I'm guessing here, but it could be that your formulas are presenting the Year/Week combo as a number, where the Match formula is looking for text (for Excel's purpose, it doesn't recognize them as the same).
You can get around this, by wrapping your formulas above with the text formula
So you'd have the following:
Results New Formula
201501 =TEXT(D1,"0")
201452 =TEXT(IF(RIGHT(M1,2) = "01",(LEFT(M1,4) - 1)&"52",M1-1),"0")
201451 =TEXT(IF(RIGHT(L1,2) = "01",(LEFT(L1,4) - 1)&"52",L1-1),"0")
201450 =TEXT(IF(RIGHT(K1,2) = "01",(LEFT(K1,4) - 1)&"52",K1-1),"0")

Related

Get working day of the month with the lowest value

I have a excel spreadsheet with two columns. One with a date and another with the value.
I want to get the working day of the month with the lowest value.
I tried to use a pivot table for it and then group the date but I get a lot of errors.
You can find the spreadsheet here and the sheet name is Historical. The others are just attempts made by me.
Spreadsheet
Thanks
The formula entered in E2 below
is
=AGGREGATE(15,6,(POWER(10,LOG10(((YEAR(D2)=YEAR($A$2:$A$3254))*(MONTH(D2)=MONTH($A$2:$A$3254)))))*$B$2:$B$3254),1)
and the array formula entered in F2 below is
=INDEX($A$2:$A$3254,MATCH(YEAR(D2)&MONTH(D2)&E2,YEAR($A$2:$A$3254)&MONTH($A$2:$A$3254)&$B$2:$B$3254,0))
I suggest to make an triple nested if-construct that checks if the weekday of the date is a workday, or the date+ 1 or the day +2. Assuming the date is in cell A4
= if(instr(weekday(A4),”23456”)>0, A4,
if(instr(weekday(A4+1),”23456”)>0, A4 + 1,
if(instr(weekday(A4+2),”23456”)>0, A4 + 2,”cannot happen”)))
Explanation: one of 3 consecutive days is always a working day.
There may be typos since I edit that on iPad without Excel available to test.
Weekday returns 1 for Sunday and 7 for Saturday. So 2-6 are workdays.
However with that simple approach you will not detect public holidays on a working day if that is a problem.
Hope I understood you question correctly. One data example with solution would have explained it better.

Excel formula stop working after x number of rows

Excel formula stop working after x number of rows
A similar question was posted 4 years ago. There were two answers. I have reviewed both. The first response is excellent but it is not the cause of my issues. The second answer was a statement that the person who responded had the same issue and what he or she did to solve it which will not work in my case. There was no explanation as to why the problem occurred.
Here is my problem. I am using the following formula:
IF(MONTH(MDB.xlsx!Date)=7,SUMIFS(MDB.xlsx!_910,MDB.xlsx!Activity,"MGRINC",MDB.xlsx!AcctNum,$Y202),0)
MDB is a Master Data Base. It currently has 214 rows but will grow substantially to probably around 5000 rows. The named ranges in the MDB are currently defined as rows 1 to 500. The above formula is in a spreadsheet, with about 300 rows. The formula works fine through row 201. From 202 on, it only returns zeros.
This is what I have done:
I have looked at constituent parts of the formula using F9, all values and arrays are reporting correctly. (That’s why the defined name range is currently set to only 500 rows, so I can breakdown a formula using F9 and not get an error after 8,192 characters.)
If I move the line with this formula from line 202 to an earlier row, it works fine.
If I delete earlier rows, the formula works fine.
This appears to be a memory issue of some sort but I don’t understand why. I have built larger and much more complex spreadsheets some of which take minutes to calculate with no issues.
Any thoughts?
Extracting the Month inside a Sumif will not work. You could add two conditions, one testing for the date being greater/equal to July 1, the second testing for the date being smaller/equal to July 31.
=SUMIFS(MDB.xlsx!_904,MDB.xlsx!Date,">="&date(2020,7,1),MDB.xlsx!Date,"<="&date(2020,7,31),MDB.xlsx!Activity,"MGRINC",MDB.xlsx!AcctNum,$Y202)
Or, you could add a column to your source data that has the month number, then test for that month number
Or, you could change the formula to use SumProduct instead of Sumif, incorporating the month filter into the SumProduct parameters like this:
=Sumproduct((MONTH(MDB.xlsx!Date)=7),--(MDB.xlsx!Activity="MGRINC"),--(MDB.xlsx!AcctNum=$Y202),MDB.xlsx!_910)
With the formula just testing form Month number, the year is disregarded, so if you have data spanning multiple years, you may want to add a parameter that checks the year.
Note that all these formulas are regular formulas and do not need to be array entered.

Excel count cells where difference between dates is between a range

I have a spreadsheet tracking issues and have various columns related to each issue, including the date the issue was discovered (column C), the date the issue actually started (column P), the date the investigation was started (column L), and the date the investigation ended and the issue was resolved (column M). I want to track how long an investigation has been open, how long it takes to complete an investigation, the time the issue started till it was discovered, and how long an issue was open; for each aspect I want to track, I'm grouping the counts into ranges (i.e., issues open 30 days or less, issues open between 31 and 60 days, etc.).
I was able to get the count of open issues using this formula (this one is for the 31 to 60 day grouping): =COUNTIFS($M:$M,"",$L:$L,"<"&TODAY()-31,$L:$L,">="&TODAY()-60)
However, I haven't been able to figure out the formula for the other things I want to track. Here's one formula I tried for tracking completion time: =COUNTIFS($M:$M,"*",$L:$L,"<"&$M:$M-31,$L:$L,">="&$M:$M-60). This formula returns 0 and when looking at the Function Arguments window, I get a #VALUE! error for Criteria2 ("<"&$M:$M-31) and Criteria3 (">="&$M:$M-60).
I'm guessing the issue is the date I'm trying to use in the second formula is not a constant like TODAY() is in the first formula but my Google skills haven't been sufficient to find an answer. Any ideas?
You're right about criterias, COUNTIFS can't handle the criteria specified as an range. The SUMPRODUCT function should be used instead. Without seeing a sample, it is difficult to say exactly, but the problematic formula could be modified as follows:
=SUMPRODUCT(($L2:$L1000<$M2:$M1000-31)*($L2:$L1000>=$M2:$M1000-60))
Use the exact range, not the entire column. You can include empty cells, but not text (eg column names) or other non numeric data that may interfere with the calculation M-31 or M-60

Trouble with looking up min value between different conditions

I am trying to find the minimum time for a fixed date between two different times.
Been trying out different variations but nothing works.
This is on excel 2016, I tried out yesterday with a similar code on a different spreadsheet (a test sheet I created) and it worked. Unfortunately it was on another laptop that I have no longer access to.
Tried out the same code on the sheet I am to use and it did not work.
{=MIN(IF((Date<=D5)*(Date>=D4);Time;"");IF((Time<=D7)*(Time>=D6);Time<""))}
{=MIN(IF(;IF((Time<=D7)*(Time>=D6);Time<""))}
D5 is the actual date I want to look at (line 1), since it did not work for my I tried out putting an earlier date in D4 but same result (line 2).
D7 and D6 is the end and start time I want to find the value between.
Tried naming the ranges so Date range refers to the dates (E2:E55220) and Time is the time range I want to find the minimum value in (C2:C55220).
Value I end up with on all attempts is 0
Alternative formula to the array. It should do the same thing:
=AGGREGATE(15,6,myTIME/((myDATE<=F4)*(myDATE>=F3)*(myTIME<=F6)*(myTIME>=F5)),1)
Now this formula works with the assumption that your dates are actual excel dates and not text looking like a date. Same goes for for time. You can test it with the following formula:
ISNUMBER(E2)
or
ISTEXT(E2)
Where E2 is a cell containing a date or a time. Excel stores dates as integers and times as decimals. IF your information is stored as text, it is probably easier to convert them first then trying to apply your formula con the converted results. you can convert withing your formula but it will tend to make the formula really ugly and long.

excel Sum every other column up to certain month

I have a Simple spreadsheet with 2 rows:
ActualJAN | BudgetJAN | ActualFEB | BudgetFEB | ActualMAR | BudgetMAR ....
100 200 300 400 500 600 ....
I'd like to sum ONLY the Budget columns up to the current month (Month(Today()).
Same for the Actual columns.
So if we're currently in February,
Budget to date would be: 600=200+400
Actual to date would be: 400=100+300
I just can't seem to get there, at least simply and elegantly.
This is a non array formula that performs array like operations. As such large range references should be avoided or you will experience a slow down or potential crash of your system. For a small defined range works great so long as the formula is not repeated too many times either.
Additionally TODAY() is a volitile function which means the formula will recalculate whenever anything in the spreadsheet changes, not just when something related to the formula changes.
This formula is generalized a bit so your data can be located anywhere on your sheet and does not require rearrangement of your data.
To get your actual sum use the following:
=SUMPRODUCT($C$4:$H$4*(COLUMN($C$4:$H$4)-COLUMN($C$4)+1<=MONTH(TODAY())*2)*(LEFT($C$3:$H$3)="A"))
To get your Budget sum use the following:
=SUMPRODUCT($C$4:$H$4*(COLUMN($C$4:$H$4)-COLUMN($C$4)+1<=MONTH(TODAY())*2)*(LEFT($C$3:$H$3)="B"))
Change C4:H4 to suit your number range. ChangeC3:H3 to suit your column title range. Change C4 to be the first cell of your number range.
Caveat: Assumes maximum 12 months starting at January
Proof of concept:
I would recommend structuring your data differently. It would be an easier task if you arrayed everything vertically and divided your data into three columns. The first would be Category, which would be populated with either "Budget" or "Actual." The next column would be Month. After that, of course, you have the Value column. Then, use a basic SUMIF, like "=SUMIF(A1:A6,"Budget",C1:C6)." A1:A6 is the range Excel will scan for the desired variable. In this case, that variable is "Budget." Then, C1:C6 is the value that corresponds to a "Budget" month. That formula will give you the answer you want as long as you expand the SUMIF formula to include the full range of values, e.g., "SUMIF(A1:A317,"Budget",C1:C317)."
So I think I understand what you're trying to do, I cannot make the entire formula without the rest of the spreadsheet but this is working currently:
For the Actual:
=IF(MONTH(TODAY())=1,A2,IF(MONTH(TODAY())=2,A2+C2,IF(MONTH(TODAY())=3,A2+C2+E2,"")))
For the Budget:
=IF(MONTH(TODAY())=1,B2,IF(MONTH(TODAY())=2,B2+D2,IF(MONTH(TODAY())=3,B2+D2+F2,"")))
Here is the spreadsheet I created to test:
If you give me the rest of the data I can complete the formula, basically all you would need to do is add more months to the formula and change the amounts it adds.
I am sure there is probably a more efficient way to accomplish this but this way works.
I suggest a hidden row to control your dates. Say, January is in column C, enter [C1] =1, [D1] =C1, [E1] =C1+1, [F1] =E1. Select E1:F1 and copy to the right until December. Hide row 1.
In row 2 use these two formulas.
[C2] ="Actual" & UPPER(TEXT("1/" & C$1,"mmm"))
[D2] ="Budget" & UPPER(TEXT("1/" & D$1,"mmm"))
Select C2:D2 and copy to the right until December. This exercise isn't required because the resulting display is exactly what you already have. But producing this result with the help of formulas ensures freedom from error, and it is faster. As an added bonus you get a visual check of what's in the hidden row.
Now you can use this formula to extract totals from row 3 where you have your values.
=SUMIFS($C3:$Z3,$C$2:$Z$2,"Budget*",$C$1:$Z$1,"<="&MONTH(TODAY()))
Change "Budget" to "Actual" and the same formula will extract the actual amounts.

Resources