View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Blue Max Blue Max is offline
external usenet poster
 
Posts: 113
Default Returning an array of unique values?

Brilliant, Harlan! Your examples opened up a whole new realm of
possibilites. Your alternate formula was much more efficient than the one
derived from the Microsoft help examples. Your samples accomplished exactly
what we needed, albeit with a few more formulas than anticipated. Now I am
wondering if there might be away to consolidate all of this into a single
formula somehow? If I make any progress I will certainly share my findings.

Thank you for the caution regarding the fact that the output could
potentially equal the size of the original database, if every entry were
unique. We had anticipated this issue and are designing this worksheet to
prevent any such problem. As to using these formulas in a complex
accounting environment, we agree with your observation. We would never
implement these formulas in a complex accounting environment. We have
accounting packages that are very adequate to our needs.

Nevertheless, these formulas are perfect for small worksheets that help
prepare our data for input into a formal accounting system. In this case,
we are designing an invoice distribution worksheet that will allow us to
quickly distribute line item charges on a vendor invoice to specific
accounts including their prorated portions of tax, shipping, handling, and
other charges. While this represents a departure from normal accounting
practices, it meets the needs of a client who desires to reflect expense
disbursements that include their prorata share of other related costs.

Thanks again,
Blue

************************
"Harlan Grove" wrote in message
...
"Blue Max" wrote...
...
. . . Nevertheless, here is an example if it will help explain your
'Yes' answers to our three questions:

The sample formula
{=IF(FREQUENCY(MATCH(A1:A8,A1:A8,0),MATCH(A1:A8, A1:A8,0))0,
INDEX(A1:A8,MATCH(A1:A8,A1:A8,0)),"")}
is entered as an array formula in the range A10:A17. The source range
A1:A8 in the formula is simply a test column of 8 cells with the
entries Banana, Apple, Apple, Banana, Orange, Pineapple, Orange, and
Nut. The formula returns a listing of unique fruits to the
destination range A10:A17 of Banana, Apple, "", "", Orange,
Pineapple, "", Nut.


You could make this more efficient by using the array formula

=IF(MATCH(A1:A8,A1:A8,0)=ROW(A1:A8)-MIN(ROW(A1:A8))+1,A1:A8,"")

As you can see, the formula successfully extracts the unique values
of the source range and keeps them properly updated in the
destination range as values are modified in the source range. The
problem here is that the resulting destination list is interspersed
with blank cells. We want to eliminate the blank cells from the
destination range and list the unique values sequentially at the top
of the range. At some point we my also wish to have the formula sort
the resulting unique values before placing them in the destination
range of cells.


The destination range COULD return as many items as the source range
if all items in the source range were distinct. So you'll need to make
due with formulas that evaluate to "" or #N/A for duplicate items in
the source list, but those values could appear below the distinct
values.

The most efficient way to load the distinct values into another range
would be with formulas like these (which also sort).

C1 [array formula]:
=INDEX($A$1:$A$8,MATCH(0,COUNTIF($A$1:$A$8,"<"&$A$ 1:$A$8),0))

C2 [array formula]:
=IF(COUNTIF($A$1:$A$8,""&C1),INDEX($A$1:$A$8,MATC H(COUNTIF($A$1:$A$8,
"<="&C1),COUNTIF($A$1:$A$8,"<"&$A$1:$A$8),0)), "")

Fill C2 down into C3:C8. Given your data in A1:A8, this fills C1:C8
with {"Apple";"Banana";"Nut";"Orange";"Pineapple";"";"" ;""}.

This technique is often useful in accounting where the user needs to
identify all the unique General Ledger Accounts in a very long list of
detail transactions which are repeatedly associated with the same set
of account numbers. . . .

...

In that case, it'd be more more efficient to use an advanced filter,
copying only the unique items in the source range to the destination
range followed by sorting the filtered, unique results. Or you could
use a pivot table to summarize fields by general ledger number if your
general ledger data were in a table.