We have a large spreadsheet that we use to calculate performance for race car drivers. It has been stable for quite some time. Today, I opened it and found that one of the tables was not calculating correctly. I tried recalculating the sheet (it is set to manual calc), and tried rebuilding the tree (ctl+alt+shift+f9) to no avail. Other formulas referencing the same named range function correctly as do other formulas using average if.
Variables
list_of_names = A list of first and last names in a single text string imported from a CSV file
local_name = A name (100% guaranteed to be included in list_of_names) to calculate an average of a drivers performance in a given sector of the track
sector_percent = A percentage of a driver's trips through a particular sector that fall into a pre-determined range
sector_count = The number of trips the driver makes though a sector
My original formula returns a #Value error. This is the original formula (the actual formula contains an IFERROR statement, but I have removed it here for clarity. The #VALUE error happens either way).
{=AVERAGEIFS(sector_percent,list_of_names,local_name,sector_percent,">0",sector_count,">"&min_number_sectors)}
After some experimenting, I have found that the following formula successfully reports the correct answer:
{=AVERAGE(IF(list_of_names=local_name,IF(sector_percent>0,IF(sector_count>min_number_sectors,sector_percent,0))))}
If you strip the list_of_names and local_name variables from the AVERAGEIFS formula, it behaves correctly (given the data that meets the criteria). This led me to believe that the list of names and the local name were not of a matching data type. However the #VALUE error still occurs if both are set to general or text. TYPE(list_of_names) or TYPE(local_name) both return 2 presently. {TYPE(list_of_names)} returns 64 as it should.
The sheet is able to perform the list_of_names to local_name function correctly in other places in the workbook and in other areas of the same sheet.
I have tried:
-Replacing all named ranges with the actual cells referred to by the name in the formula
-Referring to different local_names in the list_of_names
-INDEX(list_of_names,ROW(A1)) correctly reports the list of names when you drag it out.
-Various orders of criteria, using other criteria.
-A number of other heat of the moment changes that I can't currently recall
Essentially, the list_of_names to local_name comparison fails in this area of the sheet every time using AVERAGEIFS where AVERAGE(IF( does not.
To me the formula is correct either way, but the sudden failure in this one part of the sheet is odd.
This is my first post here and I would appreciate any help that is available. Hopefully, I have provided enough information to lead to an answer. If not, let me know and I will fill in any gaps.
Both #barryhoudini and #Jeeped are correct. I had failed to drag the information in one of the source tables far enough creating a size mismatch in the range sizes. I can't figure out how to accept that as an answer other than to answer it myself, which would not apply the proper credit where it is certainly due. I thank you both for the assistance, it was concise and excellent. I still cannot understand why one formula works and one does not. Is it possible that the AVERAGE(If has a less restrictive set of constraints when it comes to range size?
Related
I am trying to create a formula that checks for several things at the same time but I am having trouble with one part of it.
The formula is the following:
=IF(COUNTIFS($N$2:$N$17095,N3,$K$2:$K$17095,"<>"&"")>6,
IF((SUMPRODUCT(--(ROUND($K$2:$K$49,2)=ROUND(K3,2)))>9),"Always Late / Possible Automation",
IF(COUNTIFS($N$2:$N$17088,N3,$K$2:$K$17088,"<3.5")>0,"Delivered Earlier At Least Once",IF(COUNTIFS($N$2:$N$17088,N3,$K$2:$K$17088,">3.5")>6,"Always Late","False"))))
The first part checks how many entries in the range having the same value as it is in cell N3 have values different to blank and we want those to be more than 6.
Second part is the tough one, it is supposed to check how many values in the rounded range match the rounded value in cell K3. The issue is the formula checks the whole range and I want to check only for the values which match N3 (in essence like the CountIf works only for that value).
The rest is not so relevant.
Some example data:
![enter image description here][1]
As you see in the end of the table the formula with the rounding works but only because I have limited the data shown to 3 unique values in column N. Even here though if i have a blank it doesnt work becaus ei haven't considered it.
Thanks in advance.
Assuming you have Office 365 compatibility/Excel version, use a bunch of filters. To avoid an unwieldy formula I've extended ranges to maximum number of rows (customize as required)...
=LET(x_,$E$3:$E$25,a_,FILTER($E$3:$E$25,--(x_=E3)),b_,FILTER($B$3:$B$25,--(x_=E3)),IF(SUM(--(a_=E3)*(b_<>""))>6,IF((SUMPRODUCT(--(ROUND(b_,2)=ROUND(B3,2)))>9),"Always Late / Possible Automation",IF(SUM(--(a_=E3)*(b_<3.5))>0,"Delivered Earlier At Least Once",IF(SUM(--(a_=E3)*(b_>3.5))>6,"Always Late","False")))))
Note: filter does not appear to work too well within countifs for some reason (must be related to syntax RE: arrays vs. criteria TBC). Thus have replaced countifs(filter_range,X) eqn 'types' with sum(--(filter_range=X)) which works as intended.
Summary
I need an array formula that takes a row of data of certain length from Sheet1. For that row, in each column that is not blank, I need to grab the Sheet1 header value for that column and display that data in a continuous row on Sheet2 (without any spaces in between the row's cells).
Background
I have a table of data (employees and industry certifications with expiration date being the table's cell data) on sheet 1, with a row for each employee the spreadsheet is tracking. The certifications are the columns.
We are using this information to link to ID Badge Printer software (Bodno Silver), where we are limited to linking columns of data to a particular textbox.
The problem lies in the fact that not everyone has every certification. The rows are peppered with blanks separating the certifications that each employee does have. While setting up the required text boxes in the badge software template, that each link to a specific column, I quickly realized that since not everyone has every certification if we used the data how it was we would have a bunch of strange looking blanks in between the listed certifications rather than a continuous list.
What I did
My solution to this (which I'm open to a better one if anyone knows of one, other than "use better software"), was to create a new sheet and array formulas that no one would use except for me and the id printer software. This sheet would have a similar data table that took the rows of data interspersed with blank cells between expiration dates, and put the matching column headers for cells that had a date in them into a continuous row of the same maximum length (eliminating the blank cells).
Essentially, this would allow me to circumvent the restrictions of the badge software and each textbox would be MatchedCert1, MatchedCert2, MatchedCert3, etc. up to the original maximum number of certifications.
Pictures are probably better than my words at explaining what I am going for:
Sheet1 (source)
Sheet2 (result)
The array formulas
I worked on this one for a while. What I thought would be a simple INDEX, MATCH, ISBLANK formula (that I could create using the appropriate relative and absolute cell linking) and then expand to the whole sheet turned into a witch hunt and me praying for forgiveness for my sins to all that may be holy. Also a lot of googling.... I realized quickly that this one may not be so simple after all.
Finally, I arrived at the following two array formulas in order to correctly show what I was going for:
First Column of training section
{=IFERROR(INDEX(Sheet1!$E$2:$P3,1,MATCH(FALSE,ISBLANK(Sheet1!E3:Q3),0)),"")}
(easy enough, right? I thought so...)
I felt good about this until I tried to think through what would be required to get the formula to be universal so that I could use it on the entire table.
I feel dirty just putting the following in public, but here goes...
Second column through last column array formula
{=IFNA(INDEX(INDIRECT(ADDRESS(ROW($E$2),(MATCH(E3,Sheet1!$2:$2,0)+1),1,1, "Sheet1")&":"&ADDRESS(ROW(E3),COLUMN($Q3),1)),1,MATCH(FALSE, ISBLANK(INDEX(INDIRECT("Sheet1!"&ADDRESS(ROW(E3),(MATCH(E3,Sheet1!$2:$2,0)+1),1)&":"&ADDRESS(ROW(E3),COLUMN($Q3),1)),0,0)), 0)),"")}
(please don't call the police...)
[ninja edit] While this array formula works for 2nd result column through the final column, it doesn't work if there's not a blank column following the result range. The actual spreadsheet has 4 different groups of certifications that run horizontally, but I was able to just add a blank column in the corresponding data from the other sheet easily enough, so I just let it go. I'd give somebody a nickle for the answer to why that's the case here too [/edit]
Results
The first array formula, and INDEX MATCH using ISBLANK is rather straightforward.
The biggest question for me here, and the thing that drove me absolutely nuts for a couple of days, is why the second array formula requires the additional INDEX function nested inside of the ISBLANK function.
While taking the function apart and experimenting I realized that if I have any INDIRECT reference inside a ISBLANK function, which is itself inside of a MATCH function, the result of the match was ALWAYS 1:
{=MATCH(FALSE,ISBLANK(INDIRECT("$E3:$Q3")), 0)}
The above ALWAYS returns 1, whereas if I put the range in explicitly, the function would work just fine. That wasn't an option for me, since I needed to dynamically return the starting position for the match using the previous cell's address.
However, adding an INDEX function (with a column and row value of 0) to encapsulate the INDIRECT function provides the correct answer. I figured this out just by trial and error.
Questions
Can someone with more knowledge please let me know what is causing this behavior?
As a broader question, given I am limited to using formulas (no VBA), I would also like to know if I'm going about this in the wrong way or if there is a much simpler way of accomplishing this without this behemoth of a formula?
I know this sheet will probably require maintenance in a year - good luck future self!
Put this in E3, Copy over and down
=IFERROR(INDEX(Sheet1!$2:$2,AGGREGATE(15,6,COLUMN(INDEX($E:$P,MATCH($C3,Sheet1!$C:$C,0),0))/(INDEX(Sheet1!$E:$P,MATCH($C3,Sheet1!$C:$C,0),0)<>""),COLUMN(A:A))),"")
As to why your formula is not working, it is too convoluted to parse. One note, unless the sheets is the variable, one should avoid INDIRECT as much as possible. INDEX can almost always be used in its place.
Both INDIRECT and ADDRESS are volatile functions. Volatile functions will re-calculate every time Excel re-calculates, leading to a lot of unnecessary computations.
Not a solution but to answer why you are seeing this behavior:
EDIT: PREVIOUS EXPLANATION WAS JUST PLAIN WRONG
This confused me so, I did a bit of investigation:
I think that your problem is actually coming from the ISBLANK function because it is intended to be used with single values, and cannot handle ranges. Any BLANKs which are returned by functions are only converted to numeric values (0), when the BLANK is returned to (or displayed on) the sheet. If the function is returning to another function, the BLANK value seems to be preserved.
EDIT: ADDING A SOLUTION WITHOUT ARRAY FORMULAS
This is probably more complex than using an array formula... but I strongly dislike them, so do all I can to remove them.
Firstly, I would add an index to your positions in the results sheet:
=IF(F$7>COUNTIFS($F3:$L3,"<>"),
"",
IF(
MINIFS(
$F$7:$L$7,$F$7:$L$7,
">" & IFNA(INDEX($F$7:$L$7,MATCH(E9,$F$2:$L$2,0)),0),
$F3:$L3,
"<>"
)=0,
"",
INDEX(
$F$2:$L$2,
MATCH(
MINIFS(
$F$7:$L$7,$F$7:$L$7,
">" & IFNA(INDEX($F$7:$L$7,MATCH(E9,$F$2:$L$2,0)),0),
$F3:$L3,
"<>"
),
$F$7:$L$7,
0
)
)
)
)
Basically, the formula looks at the cert in the previous cell, and looks for the next, minimum index, greater than that.
I've been struggling with this longer than I care to admit, but I have a fairly simple OFFSET function call which works on one sheet, but if I copy it to a different sheet it gives a #VALUE error.
On a sheet named "Deliverable" I have this formula in a cell:
=OFFSET(Deliverable!$B$72,1,0,,3)
and it works fine.
If I go to any other sheet and use the same exact formula, or use it in the Name Manager, it gives a #VALUE error.
If I leave off the final parameter indicated the number of columns I want, it does work:
=OFFSET(Deliverable!$B$72,1,0)
but of course isn't giving me the range I need.
Any idea what's going on with this?
I'm using Excel 2016 on Windows 7.
-- Updated Info --
In a nutshell, my spreadsheet has two cells which I'm using as dropdown lists, where the 2nd cell's list feeds off the selection in the first. The data they are based on has this format:
OptionA A B C D
OptionB A B
OptionC D E F
So the first dropdown uses a simple Data Validation source pointing to the column with OptionA, OptionB, etc. Once that's chosen, the second dropdown list should contain the appropriate options for the one selected. So if OptionB is selected, then the 2nd dropdown list should show A and B.
When I initially wrote this, the data validation source was just a simple VLOOKUP entry, but the lists often had blanks since the number of options varies for each entry. Wanting to fix it up a bit, I ended up with this formula:
=OFFSET(Deliverable!B72,Deliverable!B87,0,1,COUNTA(OFFSET(Deliverable!B72,Deliverable!B87,0,1,5)))
There won't be any more than 5 options, and there are no empty cells in the middle of the data to filter out.
In one spreadsheet I have I used this as a named range definition, then specified the named range for the cells data validation source and it worked. In this other spreadsheet however, it gave me the error described earlier.
However, it looks like when I enter the statement directly into the data validation source field and not in the name manager, it works as expected.
Am I taking the totally wrong approach?
What is it that you want this formula to do? As written, it is returning a block of three horizontal cells. The #VALUE error is Excel's way of telling you "Hey, you're trying to return three cells, but I can't fit them all in the one cell that you are calling this formula from".
The reason you see a result in some places and not others is because of something called Implicit Intersection. Give it a spin on Google. But basically, it just returns whichever one of those three results corresponds to the column that the formula is entered into. If you copy that exact same formula to say row F you will see that it returns a #VALUE error there, because it doesn't know what cell it should return given the column you're calling it from doesn't match any of the cells it is returning. The fact that you don't know this indicates that the formula you're using doesn't in fact do what you think it does.
--UPDATE --
Okay, following your further clarificaiton it seems that you're talking about Cascading Dropdowns aka Dynamic Dropdowns. Lots of info on Google about how to set these up, but you may be interested in an approach I blogged about sometime back that not only provides this functionality, but also ensures that someone can't later on go and change the 'upstream' dropdown without first clearing the 'downstream' one should they want to make a change.
Note that those links talk about a slightly complicated method compared to others, but the method has it's advantages in that it also handles more levels than two, and your DV lists are easily maintained as they live in an Excel Table.
This sounds like an array equation. Try hitting Ctrl+Shift+Enter in the other sheets to validate it as an array equation.
Whenever you need to reference ranges instead of single cells, Excel needs to know that you are working with arrays.
Without VBA, I am trying to refer a range that starts at A2 and never ends. For example, if I want row 2 till row 5 i'd do
$A$2:$A$5
But what if I want the end to be open?
$A$2:??
Is this possible?
Depending on what's in A1 and what formula you're putting the reference into, you could simply use A:A. For example, if you wanted to sum all of the values in column A, but A1 contained a column title rather than a number, you could still write =SUM(A:A) and the title in A1 would just be ignored.
A2:A works in many formulas
hope that helps
If you want to refer to a range starting from A2 until max row (1048576 or 65536 for Excel prior to 2007), you can use this volatile formula... =OFFSET(A2,0,0,(COUNTBLANK(A:A)+COUNTA(A:A)-1),1) . Use formula as a defined range name or inside other formula which takes range as an argument (for eq SUM)...
Another option (in case your formula is in A1, so accessing A:A would create a circular reference) is:
OFFSET(A2, 0, 0, ROWS(A:A)-1)
This uses ROWS to count the total number of rows (without actually accessing the rows!), subtracts 1 (because we're starting with the second row), and uses this result as the height of a range created with OFFSET.
This is another option based on a formula, using the example locations in the OP's question:
=A2:INDEX(A:A,MAX(FILTER(ROW(A:A),IF(ISBLANK(A:A),0,1)=1)))
The components are the following:
=MAX(FILTER(ROW(A:A),IF(ISBLANK(A:A),0,1)=1))
which finds the number of the deepest row that is not blank, and
A2:INDEX(A:A,<expression 1 above>)
which relies on the expression above to make a bigger formula, which obtains a range starting from any location and ending at a location in the given column at the position obtained by this expression, 1.
This is an alternative to the others listed, and may be of interest as it differs from them in potentially substantial ways.
I can note the following characteristics:
It is not necessarily fast.
It seems to NOT be a volatile formula. This is important, as it means it won't necessarily be recalculated every time a calculation is made. However, I am not sure about the frequency of calculation, and don't fully understand its volatility status.
The uncertainty is related the use of the INDEX function (and, apparently, specifically after the : in a range). There are some resources that describe it.
INDIRECT and OFFSET functions are definitely volatile. There are a number of resources that describe performance implications of volatile functions, some of them mentioned in other SO answers. For example:
https://learn.microsoft.com/en-us/office/client-developer/excel/excel-recalculation
https://www.sumproduct.com/thought/volatile-functions-talk-dirty-to-me
http://www.decisionmodels.com/calcsecretsi.htm
https://chandoo.org/wp/handle-volatile-functions-like-they-are-dynamite/
It allows the user to not have to think about the data in certain cells (for example, A1, which may be meant to have a header, and not numbers).
It returns a range between the cell specified before the : and the last cell in the column that is non-blank. I think it should include non-numeric values in its consideration as well.
It shares some commonality in terms of the range it aims to identify with the answer by Kresimir L.: =OFFSET(A2,0,0,(COUNTBLANK(A:A)+COUNTA(A:A)-1),1).
To note: This answer applies to the version of Excel available as of the time of writing as part of Office 365 (and continually updated). However, the answer is based only on my own verification of its apparent correctness of my installation. I am not sure that all installations of Office 365 have the same software exactly; and I have the sense that some features may differ among different installations (even) of Office 365. I am not sure that this answer applies to everyone. Please test. I would appreciate feedback on your success with this approach.
This well covered in VBA as code below:
Range("A2", Range("A2").End(xlDown))
And if you want reach that in formula, it depends on the version number of your MS-Excel.
According to this reference number of all rows are in a sheet from Excel 2007 onwards are 1048576 that you can use bellow:
$A$2:$A$1048576
Because this range in formula is depended on Excels version, this may be different in future versions.
Finally, I suggest you use VBA.
A client of mine has a major application written and running in excel 2003 ( I know, and they know, that it is a mistake, and they are waiting for it to be properly incorporated into their SAP application. They have been waiting for many years. ). Most of the time it works fine, however this week they had a problem, and the data was returning #value entries.
As I looking into this, I identified that a DSUM function was returning #value, which was then being spread across other places ( did I mention that there is no data verification in the VBA code? ) When I looked at the function, which is summing a column in a separate sheet, with a conditional, it identified a number of problems in the data, but even when I fixed them, and the Function analysis indicated no errors, it still returned #value.
I would post some of the code, but there is a 4700 row sheet involved, which is rather inpractical. Can anyone suggest what I might be able to do to progress this? Why is the DSUM returning #value problems, when there is no indication of any errors in the source sheet? I have searched through the column, and all of the values are valid numbers.
Sorry to be a little vague, but if anyone can give me suggestions as to how to progress, it would be appreciated. Excel and VBA are not my real specialities.
The only way I could get a #value was 3 fold:
If the criteria (the 3rd parameter) contained less that 2 cells.
If the data had a #VALUE in it that was propagated through.
Or if the first row of the database/table contained a value instead of text (even a number formatted as text fails in my example).
Do you still have the offending version of the spreadsheet? Might be worth ensuring the first row of data for errors particularly cells that look like text but have values in them (i.e., cell formatting can be used to display text even if there is a value in the cell, or if the first row is also calculated).
Hope this helps, and do let us know how you get on.
Dave