04/01/2025
Unwrap a table into a single column to then chart.
There is data by year and month in A1:K13 below. You need to create a chart as below of that data. In order to do that, you must unwrap the data so that it appears in a single column as in C15 and down in the image below.
Excel has WRAPROWS and WRAPCOLS functions to turn a single column or row range into a table, but there are no functions to UNWRAP.
However, you can use INDEX and some other functions to accomplish the unwrap.
Let's start with a simple example of INDEX. INDEX(B2:K13,2,3) returns 873,540, that is, the value from the second row and third column of the range.
The source data is in an Excel Table, which has a name dtbActual. dtbActual[[2015]:[2024]) is a table reference, which is the range B2:K13.
The second argument of INDEX is
MOD(ROW(B15)-ROW($B$15)+1,12)+IF(MOD(ROW(B15)-ROW($B$15)+1,12)=0,12,0)
ROW(B15) returns 15, the row number of B15.
You copy the formula in C15 to C16:C134. Therefore, in C16, the formula contains ROW(B16)-ROW($B$15)+1, the result of which is 2.
MOD returns the remainder after dividing by a number. MOD(2,12) returns 2 as does MOD(14,12). MOD(12,12) returns 0. However, you want the second argument of INDEX to return a number 1 to 12, that is, when the number is 12 or a multiple of 12, return 12 rather than 0.
Hence, the IF function adds 12 when the the number returned by MOD(ROW(B15)-ROW($B$15)+1,12) is zero. Else, IF adds zero.
The third argument of INDEX is
ROUNDUP((ROW(B15)-ROW($B$15)+1)/12,0))
For the first 12 cells, that is, C15:C26, it returns 1. For the next 12, it returns 2, etc.
ROUNDUP rounds up to a whole number and, so, 1/12, 11/12 and 12/12 all round up to 1. 13/12, 23/12 and 24/12 all round up to 2, etc.
There is data missing in 2015, that is, certain cells are blank. Rather than returning blank for blank cells, the formula returns zero. It's not that the data were zero in those months. You don't want the chart to plot those months as zero. You can get the chart to leave a point unplotted by having /A for the value; it is not possible to have a formula return a blank, but it can return /A.
So, you can add an IF function in the form of IF(X=0, /A,X), where X is the INDEX formula. To avoid repeating that long formula twice, you can make use of LET as in LET(X, long formula, IF(X=0, /A,X))
X is any letter or word you choose.
long formula is the INDEX formula.
https://github.com/adminableowl/ExcelFreetip1017