1

I have a Selected Countries table in Calc Sheet with dropdown lists on each cell that allows me to select specific countries from a `Holidays table. I have written a formula in Cell E2 of Calc Sheet that selects the dates from those selected countries columns.

=IFERROR(INDEX(HolidayList[#All],ROW(HolidayList[#All]),TRANSPOSE(MATCH(CHOOSE({1;2;3;4;5},$A$2,$A$3,$A$4,$A$5,$C$2),TRANSPOSE(HolidayList[#Headers]),0))),"")

In column L, I have written a formula to merge the selected countries dates and create a single date column of Unique Distinct values (non-duplicates).

=IFERROR(SMALL(SelectedHolidays,ROW(INDIRECT("1:"&COUNT(SelectedHolidays)))),)

This formula automatically lists all the dates without me having to drag the formula down to each cell. I need someone to help me modify this formula to generate a single list of unique distinct dates column. I don't need a formula that i have to drag down to subsequent cells.

I have also listed on a NamedRanges Sheet, the named ranges i have created in the workbook.

Here is a sample workbook attached for your perusal.

Edit:

I was able to workout a unique list of dates without dragging down the formula using the FREQUENCY function. However, there are #Values (for duplicates) in the rows array produced by MATCH in formula. How do i exclude the #Values in this array?

=SMALL(MDHolidays,IF(FREQUENCY(MDHolidays,MDHolidays)>0,MATCH(MDHolidays,MDHolidays,0),""))

3 Answers 3

2

For your first question, you can simply hide zero values by formatting your cells as m/d/yyyy;;. However, your formula can be amended to exclude the TRANSPOSE function...

=IFERROR(INDEX(HolidayList[#All],ROW(HolidayList[#All])-MIN(ROW(HolidayList[#All]))+1,MATCH(CHOOSE({1,2,3,4,5},$A$2,$A$3,$A$4,$A$5,$C$2),HolidayList[#Headers],0)),"")

For your second question, select cells L2:L33, since there's a maximum of 32 possible values, enter the following formula, and press Ctrl + Enter...

=IFERROR(SMALL(IF(SelectedHolidays>0,IF(ISNA(MATCH(SelectedHolidays,L$1:L1,0)),SelectedHolidays)),1),"")

EDIT

I'm a little confused as to why you're using MDHolidays, instead of SelectedHolidays. In any case, you can amend the the latest formula you've posted as follows...

=IFERROR(SMALL(IF(FREQUENCY(IF(MDHolidays>0,MATCH(MDHolidays,MDHolidays,0)),ROW(MDHolidays)-MIN(ROW(MDHolidays))+1)>0,MDHolidays),ROW(INDIRECT("1:"&COUNT(MDHolidays)))),"")
Sign up to request clarification or add additional context in comments.

1 Comment

I'm a little confused as to why you're using MDHolidays, instead of SelectedHolidays. In any case, you can amend the the latest formula you've posted as follows... yes, i didn't have any alternative solution, except this one. Thanks for yout solution. The only problem is, if i don't add it as a dynamic Named Range, and use this unique range in a WORKDAY() function, i get a #VaLUE! error. That is because of the #NUM values at the end of this range.
1
  1. We can get rid of zeros aka 1/0/1900 in column L by adding COUNTIF(SelectedHolidays,0) to row number, getting

=IFERROR(SMALL(SelectedHolidays,COUNTIF(SelectedHolidays,0)+ROW(INDIRECT("1:"&COUNT(SelectedHolidays)))),"")

  1. We'll get a distinct Holidays range adding an additional column (for example, M) with an array formula

=IFERROR(INDEX(MDHolidays,MATCH(0,COUNTIF(M$1:M1,MDHolidays),0)),"")

4 Comments

=IFERROR(INDEX(MDHolidays,MATCH(0,COUNTIF(M$1:M1,MDHolidays),0)),"") requires me to drag down the formula, which i don't want to do. Any alternative to this like the one above which uses SMALL with INDIRECT?
@sifar added an edit but it didn't actually work, sorry :), removed it
no worries. see my recent Edit in my post. Hope you have an idea how to exclude the #Values in the array.
@sifar I also got close to the desired result with help of some additional columns and using SMALL, SUMIFS and INDEX but I got #VALUE when changing "L2:L22" to MDHolidays.. I think Domenic came up with a nice solution though.
1

EXCEL 365 Method -----------------------------

UNIQUE treats each row or column as a "tuple" and then compares each tuple, so when you put a matrix into it such as A1:C3, it looks either row-wise (e.g. {A1,B1,C1} vs {A2,B2,C2} ) or columns-wise (e.g. {A1;A2;A3} vs {B1;B2;B3} ) to determine if a tuple is unique. It does not look at each of the cells, so you have to multiplex the cells into a single column (or row) and then apply UNIQUE to that multiplexed range.

Here is a formula that you can put into L2 that will deliver a dynamic array of unique dates based on your XLS (thanks for sharing - that made this a lot easier to understand):

=LET( range, E3:I9,
       Cols, COLUMNS( range ),
       Rows, ROWS( range ),
       iSeq, SEQUENCE( Rows * Cols,,0 ),
       RowIndex, iSeq / Cols + 1,
       ColIndex, MOD( iSeq, Cols ) + 1,
       rawList, UNIQUE( INDEX( range, RowIndex, ColIndex ) ),
       SORT( FILTER( rawList, ( rawList <> "" ) * ( rawList > 0 ) ) )
      )

I set range = E3:I9 so that it includes up to Belgium in your output - not sure if that is what you are trying to achieve.

This LET formula takes in range as a variable and then it measures its dimension.

Modulation & Multiplexing

It then prepares the modulation so that range can be multiplexed into a single column. iSeq is the sequence that counts each cell in the range and that will be modulated vertically into RowIndex and horizontally into ColIndex. These are used to multiplex range by applying INDEX( range, RowIndex, ColIndex ).

Applying UNIQUE and Filtering

rawList applies UNIQUE to the multiplexed column to arrive at the unique values but... these will contain some undesirable outputs such as blank and 0 that need to be filtered, so the result is delivered as the filter of rawList. The final output is then sorted.

Also, with this formula, you can change your count of unique dates formula in N2 to =COUNTA(L2#).

EXCEL 2013 Method (Plumhoff-Bartholomew) ----------------------------

Your MDHolidays is now going to become a set of helper cells using the same name that you have given it (let's not rename it for now or it will get confusing). We are going to use two more helpers to:

  1. Generate a set of unique dates
  2. that are free of zero-value dates

First, create two new named ranges:

k is an old-school sequence generator based on row

= ROW( MDHolidays ) - 1

unique.idx is boolean mask of k that eliminates duplicates, blanks and zero-dates:

= IF( ISNUMBER( MDHolidays ),
         IF( ( MATCH( MDHolidays, MDHolidays , 0 ) = k ) * ( MDHolidays <> 0 ), 
               k ) )

These two can be created as named ranges without placing them anywhere. Just open Name Manager and create them as new names with the formulas above.

Now, you can create your output. You can test this in cell M2. It will be:

= IFERROR( INDEX( IF( MDHolidays > 0, MDHolidays ), SMALL( unique.idx, k ) ), "" )

If you like the result, then let's do a final clean-up. Rename MDHolidays to MCHolidays (merged, consolidated holidays) and then open Name Manager and replace your current dyn range formula for MDHolidays: =OFFSET(Calc!$L$2,0,0,COUNTA(Calc!$L:$L)-1) with your current (and very good) formula in L2 =IFERROR(SMALL(SelectedHolidays,ROW(INDIRECT("1:"&COUNT(SelectedHolidays)))),). This will virtualize those values so that they don't take up any cell-space.

Now you can reuse your old MDHolidays name by opening Name Manager, creating a new MDHolidays with the formula that is currently in M2 above. To complete the clean-up, change the formula in L2 to simply = MDHolidays and delete the formula in M2.

This method of teasing out UNIQUE was developed by Bernd Plumhoff and Peter Bartholomew.

14 Comments

Are LET & UNIQUE new functions in Excel? Will they work in Excel 2013/2016?
Ahh OK - yes, they are both released after Excel 2016. LET just makes the formula easier to manage without helper cells, so there is a workaround to it. However, working around UNIQUE requires more effort. It will require helper cells tmk or, you can create your own version with VBA. e.g. here
Thanks Mark. I wish i could. However, it is an xlsx workbook that in which this formula is needed.
Also, FILTER and SORT only work post Excel 2016 - so, this will not work for you even if you flatten the LET into a formula.
I accidentally hit RETURN while typing the last comment and we crossed each other - sorry. I will have to look at your new version. Also, it could be that there is a better way to consolidate MDHolidays without the helper range, but I was looking for something expedient that built on what you have already done.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.