moizs,
Glad to help you..
But did you check the formula by adding some new data at 'sales' and 'sales Return' sheet?
Anyways, here is the explanation for the formula at A2 of 'Report' sheet:
Note: I assume, you have already understood the dynamic named range formulas (with offset-counta) which I already explained in one of my aforementioned posts.However, please let me know if you need any further explanation for the same.
The entire formula is:
=IFERROR(IFERROR(INDEX(dynlist1,MATCH(0,COUNTIF($A$1:A1,dynlist1),0)),INDEX(dynlist2,MATCH(0,COUNTIF($A$1:A1,dynlist2),0))),"")}
Let's break it up and understand it step by step:
the first part:
INDEX(dynlist1,MATCH(0,COUNTIF($A$1:A1,dynlist1),0))
The COUNTIF($A$1:A1,dynlist1)partreturns an array containing either 1 or 0 based on if $A$1:A1 is found somewhere in the array dynlist1
becomes:
COUNTIF("Customer Name",{A; A; B; B; C; C; D; D; F; F} )
and returns:
{0;0;0;0;0;0;0;0;0;0}
This means the cell value in $A$1:A1 can´t be found in any of the cells in the named dynlist1. If it had been found, somewhere in the array the number 1 would exist.
Note:As you know, the match formula returns the relative position of an item in an array that matches a specified value.
Hence, MATCH(0,COUNTIF($A$1:A1,dynlist1),0) becomes:
(0,{0;0;0;0;0;0;0;0;0;0},0)
and returns 1 (We are getting this value for the first 0 in {})
Now =Index(dynlist1,1) becomes:
=Index({A; A; B; B; C; C; D; D; F; F},1)
And it returns A
The same logic is applied in second part where we have used dynlist2.but this part comes under 'value_if_error' argument of iferror formula.
Now see how we have used IFERROR in this formula.
=iferror(value, value_if_error)
=iferror(INDEX(dynlist1,MATCH(0,COUNTIF($A$1:A1,dynlist1),0)),INDEX(dynlist2,MATCH(0,COUNTIF($A$1:A1,dynlist2),0)))
Here,
value = INDEX(dynlist1,MATCH(0,COUNTIF($A$1:A1,dynlist1),0))
value_if_error = INDEX(dynlist2,MATCH(0,COUNTIF($A$1:A1,dynlist2),0))
Finally we wrap the entire formula with another iferror (for 2007 version; you have to use if(iserror...in case you use 2003 version). We have used IFERROR to return blank[()= empty string] in case any error happens.More precisely, since we are dragging it say for more 300 rows at report sheet but we do not have 300 unique customers either in sales or sales return sheet, we would obviously get error after the formula does not find any match. To tackle this, we have used iferror to return blank if error happens
Note: In countif part of the formula, we have used relative and absolute reference Because of which, When you copy the array formula down the countif formula range ($A$1:A1) expands.
The first cell, A2: COUNTIF($A$1:A1,dynlist1)
Second cell, A3: COUNTIF($A$1:A2,dynlist1)
and so on.
Hope I am able to explain the logic, to some extent, to you...
Regards,
Kaushik