Index Match Group Issue - excel

I have a range of data where column N displays the unique order number values, column F contains an Action. If the Action value for any of the related order numbers is the same as any other for that group I want to mark these up as , rejected, false, 0 whatever so that I can remove them from the dataset.
In the example graphic I have manually entered True or False in Column Q, but as I have over 10,000 rows, I think I may need a simple formula.
Can someone please advise how to achieve this
Many thanks

You could check number of lines with the same combination of Action and Order No. with this formula:
=COUNTIFS(N:N;N2;F:F;F2)
it will give you number of occurences of the combination, so you just need to filter all numbers greater than 1 or change the formula to give rejected, 0, false or whatever you like if the value is greater than 1.

In a new column, creat concatenate of column F and column N, For example, the new column is R then in cell Q1 put the value 1 and starting from Q2 paste this formula =IF(R1=R2,Q1+1,1)
Once the formula is dragged you can keep only one occurrence of the concatenated value and delete other.Snip from the Excel file
2nd snip attached here

Requirements:
Flag as Delete, all Order numbers with a duplicated Action value.
Assuming the data is located from rows 2 to 10105 (over 10,000 rows).
Solution – Array Formula:
This Array Formula will return (eventually) the required results:
= IFERROR( IF( MATCH( $N28,
IF( COUNTIFS( $N$7:$N$10105, $N$7:$N$10105, $F$7:$F$10105, $F$7:$F$10105 ) > 1, $N$7:$N$10105 ), 0 ) > 0,
"Delete" ), "" )
Unfortunately, the performance of an Array Formula pointing several times to a range of over 10,000 cells will be extremely slow.
To test the Array Formula over a much smaller range (24 rows only) enter this version of the formula in Q2 then copy it to Q3:Q25:
= IFERROR( IF( MATCH( $N2,
IF( COUNTIFS( $N$2:$N$25, $N$2:$N$25, $F$2:$F$25, $F$2:$F$25 ) > 1, $N$2:$N$25 ), 0 ) > 0,
"Delete" ), "" )
Solution – Standard Formulas:
The alternative solution would be to use two columns to flag the required records:
To identify the orders with duplicated Action, enter this formula in Q2 then copy it to Q3:Q10105:
= IF( COUNTIFS( $N$2:$N$10105, $N2, $F$2:$F$10105, $F2 ) > 1, $N2, "" )
To flag as Delete all Order numbers identified in step 1, enter this formula in R2 then copy it to R3:R10105:
= IFERROR( IF( MATCH( $N2, $Q$2:$Q$10105, 0 ) > 0,"Delete" ), "" )

Related

Multiconditional, dictionary-based, count in Excel 2019

Excel coding gurus, can someone help me count in Excel? :) I need a count, based on multiple, dictionaty depandant, conditions.
What I have:
I have an Excel 2019. Not the 365 edition.
I have an Excel sheet called, say Dicts with a table of 2 columns. I is a dictionary. Column I contains list of people. And each person in the I column has the country of his/her origin denoted in the correspondent cell of H column.
For a better view check this picture, plz.
And I have a DataSheet, that contains records of various persons from the dictionary table along wiht some data on each record.
For a better view check this picture, plz.
Now, the question is:
How can I count the number of all the citizens of USA and Iitaly in the column A that have either Y or M in the correspondent cell of Column B?
You could use the following in Office 365:
=LET(condition1,FILTER(A2:A25,MMULT(--({"Y","M"}=B2:B25),SEQUENCE(2,,1,0))),
condition2,FILTER(Table1[C2],MMULT(--({"USA","Irtaly"}=Table1[C1]),SEQUENCE(2,,1,0))),
SUM(--(TRANSPOSE(condition1)=condition2)))
In Excel 2019 you could use the following:
=SUM(
--(TRANSPOSE(INDEX(Table1[C2],
AGGREGATE(15,6,ROW(Table1[C1])-1/(MMULT((--(Table1[C1]={"USA","Irtaly"})),ROW(1:2)^0)),
ROW(A1:INDEX(A:A,SUMPRODUCT(--({"USA","Irtaly"}=Table1[C1])))))))
=INDEX(A2:A25,
AGGREGATE(15,6,ROW(A2:A25)-1/(MMULT((--(B2:B25={"Y","M"})),ROW(1:2)^0)),
ROW(A1:INDEX(A:A,SUMPRODUCT(--({"Y","M"}=B2:B25))))))))
In Excel versions prior to Office 365 this formula needs to be entered with ctrl+shift+enter
Change the Table name and references to your needs (I can't reproduce the characters used and Table Name is nowhere mentioned)
When using different system language using different separators use the following:
=SUM(
--(TRANSPOSE(INDEX(Table1[Стовпець2];
AGGREGATE(15;6;ROW(Table1[Стовпець1])-1/(MMULT((--(Table1[Стовпець1]={"USA"\"Irtaly"}));ROW(1:2)^0));
ROW(A1:INDEX(A:A;SUMPRODUCT(--({"USA"\"Irtaly"}=Table1[Стовпець1])))))))
=INDEX(A2:A25;
AGGREGATE(15;6;ROW(A2:A25)-1/(MMULT((--(B2:B25={"Y"\"M"}));ROW(1:2)^0));
ROW(A1:INDEX(A:A;SUMPRODUCT(--({"Y"\"M"}=B2:B25))))))))
I can imagine you're looking for something simpler, but what about this (pseudocode, based on COUNTIFS() worksheet function):
=COUNT_Multiple_Criteria(range,country="USA", done="Y") +
COUNT_Multiple_Criteria(range,country="USA", done="M") +
COUNT_Multiple_Criteria(range,country="Italy", done="Y") +
COUNT_Multiple_Criteria(range,country="Italy", done="M")
Assuming:
The table in sheet Dicts is named loPeople with fields: Country and People
The data in sheet DataSheet is located in a table named loDone with fields: Name and Done
Try this formula:
= SUM( IFERROR( IF(
MATCH( loDone[Done], {"M","Y"}, 0 )
* MATCH( INDEX( loPeople[Country],
MATCH( loDone[Name], loPeople[People], 0 ) ), {"Ctry.C","Ctry.E"}, 0 ),
1 ), 0 ) )
Dynamic Formula: If a dynamic formula is required, let's assume that:
The Country criteria is located in a table*{a}* named: loSelCtry
The Done criteria is located in table*{a}* named: loSelDone
Try this formula:
= SUM( IFERROR( IF(
MATCH( loDone[Done], loSelDone, 0 ) *
MATCH( INDEX( loPeople[Country],
MATCH( loDone[Name], loPeople[People], 0 ) ), loSelCtry, 0 ),
1 ), 0 ) )
*{a}Using tables for the criteria enhances the dynamics of the formula.
Let's try the following approach. In cell: H4 put the following formula:
=SUMPRODUCT(
N(ISNUMBER(MATCH(INDEX(A3:A8, MATCH(D3:D7, B3:B8,0)), H2:I2,0))),
N(ISNUMBER(MATCH(E3:E7,H3:I3,0)))
)
Here is the output:
The formula uses valid functions for Excel 2019, but that is not enough, you need to validate the expected behavior. After dynamic array behavior was introduced for most of the functions the output should be different. In such cases you can try the legacy approach: Ctrl+Shift+ENTER to ensure a dynamic array output.
If that doesn't work then an alternative is to use MMULT as follow, assuming IF returns a dynamic array for your Excel version:
=SUM(MMULT(TRANSPOSE(IF(INDEX(A3:A8, MATCH(D3:D7,B3:B8,0))=H2:I2,1,0)),
IF(E3:E7=H3:I3,1,0)))
that SUM per country all names with Y or M.
Explanation
Let's use the LET function for better understanding:
=LET(lkUpC, H2:I2, lkupD, H3:J3, countries, INDEX(A3:A8, MATCH(D3:D7, B3:B8,0)),
cCnts, N(ISNUMBER(MATCH(countries, lkUpC,0))),
dCnts, N(ISNUMBER(MATCH(E3:E7,lkupD,0))),
SUMPRODUCT(cCnts, dCnts)
)
The name countries finds the corresponding countries for the Dataset columns. The name cCnts returns an array with the same number of rows as countries having 1 for LkUpC match values otherwise 0. Similarly dCnts the Done counts based on lkUpD. Both arrays have the same size, so we can invoke SUMPRODUCT to count the number of items that satisfy both conditions (columns D and E are highlighted in yellow in the above screenshot)

Excel formula to extract Unique Distinct values from a Date column without dragging down

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),""))
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)))),"")
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)))),"")
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)),"")
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:
Generate a set of unique dates
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.

How to add values for alternative cells in Excel column?

In an Excel sheet, I want to add values A1, C1, E1 and so on.
I tried with
=IF(MOD(ROW(), 2) = 0, 1, 0)
I want to add values of H2,J2,L2,N2,P2 and all alternative cells.
Like that I2,k2,m2,o2 abd all alternative cells. Image attached.
Excel Image
One way of solving your issue is to use SUMPRODUCT.
=SUMPRODUCT((A1:L1)*(MOD(COLUMN(A1:L1),2)<>0))
Replace A1:L1 with the relevant range on your worksheet.
It will be better if you can provide some sample data and expected output next time :)
You need an array formula. (I'll use A1:E1 as the example range). First we need to assign either 1 or 0 to each cell.
Mod(Column(A1:E1),2)=0
Then we multiply each cell by that 1 or 0 to give either the cell value or zero as the result
a1:e1*mod(column(a1:e1),2)=0
Then we Sum them
=SUM(A1:E1*(MOD(COLUMN(A1:E1),2)=0))
and finally we enter this as an array formula by entering it using Control Shift Enter
Assuming that the range you want to add is A1:A10 try this FormulaArray
= SUM( $A$1:$A$10 * ISODD( ROW( $A$1:$A$10 ) ) )
or this if the range is A1:Z1
= SUM( $A$1:$Z$1 * ISODD( COLUMN( $A$1:$Z$1 ) ) )

Check if row number increases, Excel

I'm looking for a way or ideas (preferable array solution), where you can determine if the numbers in a row increases.
The excel formula should give me "True" for the following sequence, since I want it to exclude #N/A values.
Example:
0,22 0,275 0,3162 0,36 #N/A 0,46 0,52
Notice:
I saw an reddit post "Formula to detect if row values are increasing?" with a similar question. I liked the idea and I have tried to use it with my numbers, but don't get the formula to work/understand it fully.
I am not sure if it can be done in one array formula, because the possibility to have N/A values causes some additional complexity. I can suggest a solution with a helper column though. Say your list of values is in A1:A7, then you can get the sign of the difference between the value in A2 and the value in A1 as follows:
= IF( ISNUMBER( A2 ), SIGN( A2 - LOOKUP( 2, 1 / ISNUMBER( A$1:A1 ), A$1:A1 ) ), 0 )
if you put this formula in B2, you can drag this down to B7. Now if you compare the sum of B2:B7 with the number of increases you expect, you have your answer:
= SUM( B2:B7 ) = COUNT( A1:A7 ) - 1
Refer to this very helpful page to get an explanation of how to get the last non-blank (c.q. numeric) value in a range.

Excel - Making a sublist based on a text filter

I am trying to implement something similar to what is explained in this article:
http://exceltactics.com/make-filtered-list-sub-arrays-excel-using-small/
For this example, column B has Text, column c has integer values, and column d has text
The formula below works for filtering on values that are >= 1 in column C of my data:
=IFERROR(
INDEX(
B$2:B$11,
SMALL(
IF(
$C$2:$C$11>=1,
ROW(B$2:B$11)-ROW(B$2)+1
),
ROWS(B$2:B2)
)
),
""
)
I would like to replace that line with a search function that filters based the text content of a cell (from column D). The following works on a single line (returns 0 if "a" is not contained in the cell, otherwise a value greater than 0).
=IFERROR(SEARCH("a",$D2),0)
However, combining it with the first function doesn't work:
=IFERROR(
INDEX(
B$2:B$11,
SMALL(
IF(
IFERROR(SEARCH("a",$D$2:$D$11),0)>=1,
ROW(B$2:B$11)-ROW(B$2)+1
),
ROWS(B$2:B2)
)
),
""
)
What am I missing from this formula?
There is nothing wrong with the formula IMHO. It worked for me, but I did have problems when I tried to change the original formula in-place with the range selected. If you start off in a new area in the worksheet or just select the top cell in the original range and then pull it down once you've changed it, it's fine. With the range selected, it didn't change the final B2 to B3 etc. as I pulled it down, so just kept getting the first row number repeated.
BTW don't need the ">=1" in the modified part of the formula because any match will give a result >0 which is equivalent to "true"
IFERROR(SEARCH("a",$D$2:$D$11),0)
See also suggestion for changing the array formulae to ordinary ones before changing them
Changing array formulae

Resources