(the answer is completely reedited after the discussion in the comments)
The OFFSET function is of no use here, as it operates with ranges and not with individual cells.
For the SUM function, everything is quite easy {=SUM(A1:C3*(COLUMN(A1:C3)=D1:D3))}
. Or you might even avoid using the arrays with =SUMPRODUCT(A1:C3,(COLUMN(A1:C3)=D1:D3))
. Note that column D now should refer to a specific column number and not to an offset from the first column, i.e. 1;2;3
.
For other functions, it's more difficult a) because they count zeros (false values) from the matrices; b) because they usually don't work with non-contiguous arrays (and any attempt to exclude zero-values from the matrix runs into the #value error). However, the combination of FREQUENCY and INDEX does the trick:
- finding average:
{=(SUM(A1:C3*(COLUMN(A1:C3)=D1:D3)))/INDEX(FREQUENCY((A1:C3*(COLUMN(A1:C3)=D1:D3)),0),2)}
- finding median:
{=MEDIAN(LARGE((A1:C3*(COLUMN(A1:C3)=D1:D3)),ROW(INDIRECT("1:"&INDEX(FREQUENCY((A1:C3*(COLUMN(A1:C3)=D1:D3)),0),2)))))}
Hope it helps.