On the Wonders of IFERROR()

If you’re spreadsheet is meant to be looked at by other people, you should just about nest everything in an IFERROR([formula],).  The nothing after the comma means that in the case that your formula throws an error (#VALUE, #N/A, #REF!, et cetera), nothing shows up in the cell.  No distracting error text.

Now, this doesn’t mean you shouldn’t debug your formulas first, but if there are normal cases where they might throw some of these errors, IFERROR() is invaluable.  (e.g. I have a dynamically updating query list and I know that sometimes the query will return nothing).

On the Quirks of INDEX()

I’ve been working on a self-updating bi-weekly deliverables calendar / dashboard in Google Spreadsheets for my office the past few days.  Our Traffic Manager can simply add projects and their various deliverables to other sheets which serve as databases. Then another sheet, which one of our animator a painstakingly organized for aesthetics, will search those databases to pull deliveries to their correct dates and color-coding based on other information associated with those projects.  This sheet updates itself based on the current day and week.

Recently, a switch I made from INDEX(FILTER(SORT(…))) to INDEX(QUERY(…)) for minimization purposes resulted in some peculiar behavior.

But first a preface as to why I am using INDEX for array formulas that are perfectly capable of expanding themselves down multiple rows.  Our animator has used the spreadsheet as a grid to help align elements, merging some cells and leaving some as borders.  This means that the cells no longer behave like a sequential spreadsheet.  For example, merged cells behave as only their top left cell.  Net result is that I need to write a specific formula for each identified locus of data.  Somewhat more time-consuming but not un-doable.

Anyway, so I was using INDEX() to return whole rows from my QUERY() via INDEX(QUERY([array], “select Col[#],Col[#] where …”),1).  This worked fine when the QUERY() pulled more than one row; however, when the QUERY() only pulled a single row, INDEX() only pulled the first entry where I wanted the whole first row, and where it would have pulled the non-existent second r0w, it pulled the single entry from the second column.

I cannot confirm my suspicion, but I surmise that QUERY(), as written by the programmer returns a one dimensional array when there is only one row of results and a two dimensional array when there are more.  This inconsistency means that INDEX(), when passed only a single number, pulls that index from an array, resulting in a single element from a one-dimensional array, and a whole row (or sub-array) in a two-dimensional array.

Unfortunately, to a naive user on the front-end who expects that number of their INDEX() function to always refer to a row, this is confusing and un-beneficial. I have not figured out how to solve this problem yet, and instead have broken up my QUERY() to multiple ones that only query single columns, thus guaranteeing that the dimensions of returned arrays are always 1xN.  It has maximized rather than minimized my formulas, but is more robust for the time being.

Geometry 1/13/2014

Something that I’ve been trying to figure out what to do with is my affinity for random geometric problems (e.g. staring at a half-covered design on a random pizza box and realizing that the lines of the “pizza slices” do not intersect at the center of the arc in which they lie).

Today, I was pondering over the toroidal map type in Civilization. The game still plays on a planar rectangular projection of the map, but how much distortion should there really be?

I’m going to assume that the width of the map is the maximum latitudinal circumference around the outside, and therefore I am interested in how much narrower the “poles” should really be to meet each other on the inside of the torus.

My initial condition therefore is that [map width] = 2 * pi * ([major radius] + [minor radius]) and that [map height] = 2 * pi * [minor radius].

I am interested in the minimum latitudinal circumference, described by 2 * pi * ([major radius] – [minor radius]).

After some very basic algebra, the conclusion is that the poles should be only as wide as [map width] – 2 * [map height], a significant result! The distortion is quite severe for maps of appreciable height!

If a toroidal Civ map was twice as wide as it was tall, the poles would all still come to a single point, which is not much actual space for units and cities placed up there. Though, if we had to play on Civ maps where distance was physically accurate given the 3D shape of the world, it’d probably be even more confusing to keep track of.

scan_01142014

A not actually very informative scan from my scribbles