Excel Formula: check for every Col1 unique value, if COL2 has duplicates, then Col3 should not be unique - excel

Consider the following data. I have added help text across each data row to explain scenarios: Bill is Col A, Ref is col B and so on
Form: is Formula; Exceptns: With Current Formula the results I get and expected output is what I'm looking at
Bill Ref Ref2 HelpText Form Form Excptns Excepted output
123 557 123 Scenario1 1 1 FALSE FALSE
123 589 123-1 Scenario1 1 1 FALSE FALSE
123 591 123-2 Scenario1 2 1 TRUE FALSE
123 591 123-3 Scenario2 2 1 TRUE TRUE
124 432 124 Scenario1 1 1 FALSE FALSE
124 433 124-1 Scenario1 1 1 FALSE FALSE
Scenario1:
Since they have same bill number and unique Ref Number, Ref2 column has to be unique
Scenario2:
Since same bill number and same ref number, we can't have unique Ref2 values - therefore (it should be 123-2 and not 123-3 and I need to identify all such cases using excel formula)
Duplicates scenario will not exist as we are taking pivot
My effort:
A B C D E F G
Bill REf Ref2 HelpText Formula Formula Formul
123 557 123 Scenario1 =countIFS(A:A,A2,B:B,B2)
123 589 123-1 Scenario1
123 591 123-2 Scenario1
123 592 123-2 Scenario2
I used countifs(A:A,A2,B:B,B2) in columnE
countifs(B:B,B2,C:C,C2) in columnF
columnG FORMULA is =AND(IF(E2>1,"TRUE","FALSE"),IF(F2=1,"TRUE","FALSE"))
when I FILTER Column G by true/false - true means exceptions:
I get both instances as output. I'm however not interested at the first occurrence because it's valid. From there on, 2nd and incase 3rd instances - I will be interested
Please help me arriving at the formula of how can I can ignore the first occurrence. I can not use VBA. Only excel formulae - and no limit on column numbers

Related

In VBA, check matches by grouping variable

I need to produce a new column that checks for matches in the m1, m2 columns, per ID and returns a character, depending on matching status. So, for each ID, if m1, m2 match values, return 'a', if m1 = 'No', return 'b' and if m2 = 'No', return 'c'.
Example below
ID m1 m2 new_col
111 1 1 a
111 2 2 a
222 1 1 a
222 No 2 b
222 2 3 a
333 1 No c
333 2 1 a
333 3 2 a
333 4 3 a
You can use a formula to calculate the new column:
Assuming your data starts at A2, here is the formula for E2:
=IF(IF(B2="No","b",IF(C2="No","c",COUNTIFS($A$2:$A$10,A2,$B$2:$B$10,C2)))=1,"a",IF(B2="No","b",IF(C2="No","c",COUNTIFS($A$2:$A$10,A2,$B$2:$B$10,C2))))
Note that the formula only checks the first 9 rows based on your sample data.
Also note that the 5th line (222\2\3) has an unknown result because none of the criteria match.
Here is the output with the formula:

Create two new Dataframes from existing one based on unique and repeated values of a column

colA colB
A 125
B 546
C 4586
D 547
A 869
B 789
A 258
E 123
I want to create two new dataframe and the first one should be based on the unique values in 'colA' and the second one should be the repeated values of 'colB'. The colB has no repeated values. The first output is like this:
ColA colB
A 125
B 546
C 4586
D 547
E 123
The second output is like this:
colA colB
A 869
B 789
A 258
For the first group, use drop_duplicates. For second group, use duplicated:
print (df.drop_duplicates("colA"))
colA colB
0 A 125
1 B 546
2 C 4586
3 D 547
7 E 123
print (df[df.duplicated("colA")])
colA colB
4 A 869
5 B 789
6 A 258

excel match index if exists

I have 2 excel sheets:
Sheet1: (Value = Prevalue)
Id Preval Value
111 1 1
123 2 2
100 3 3
Sheet2:
Id Num Date
111 5
123 6 1/1/18
100 7
I want to perform a logic saying that: Matching the 2 sheets by Id, if Date on sheet2 exists then Value on sheet1 = num on sheet2 else = Prevalue
Id Value
111 1 (same)
123 6 (update since date exists)
100 3 (same)
How would this be done using index or vlookup? Many thanks!
Try this formula:
=IF(VLOOKUP(A2,Sheet2!$A$1:$C$4,3,0)="",B2,VLOOKUP(A2,Sheet2!$A$1:$C$4,2,0))

Returning next match to a equal value in a column

I often need to search through columns to find the match to values and then return the according value.
My issue is that INDEXand MATCHalways return the first value in the column.
EX. I got 7 car dealers and this is the sales last month. Oslo and Berlin sold the same ammount and INDEX(D:E,MATCH(B1,E:E,0),1)) in column C will return the first hit from column D.
A B C D E
rank Sales Delaer
1 409 London | Tokyo 272
2 272 Tokyo | London 409
3 257 Hawaii | oslo 248
4 255 Stockholm | numbai 240
5 248 Oslo | Berlin 248
6 248 Oslo | hawaii 257
7 240 Numbai | Stockholm 255
At the moment my best solution is to first find the row each value in B got in E with MATCH(B1,E:E,0) and add that to a new column (column F). Then I can add another formula in the next column, which is what I currently have to do:
=IF(F2=F1;MATCH(F2;INDIRECT("F"&(1+F1)):$F$7;0))+F2
Is there a better approach at this?
In B2 use the following standard formula,
=IFERROR(LARGE(E$2:E$8, ROW(1:1)), "")
Fill down as necessary.
In C2 use the following standard formula,
=INDEX(D$2:D$8, AGGREGATE(15, 6, ROW($1:$7)/(E$2:E$8=B2), COUNTIF(B$2:B2, B2)))
Fill down as necessary.
        
[Optional] - Repair the ranking in column A.
In A2 use the following formula,
=SUMPRODUCT((B$2:B$8>=B2)/(COUNTIFS(B$2:B$8, B$2:B$8&"")))
Fill down as necessary.
        

Sort 2 Columns + Adj Column by matching Numbers

I have a long list of ID number in Column C with important information in Column D-Q.
I need to sort it accordingly to a specific set of ID numbers in Column B along with the matching information in Col D-Q, like this:
I have this:
B C D E . . .
123 234 male 12
234 345 female 13
345 555 male 12
444 123 male 11
I need this:
B C D E . . .
123 123 male 11
234 234 male 12
345 345 female 13
444 N/A N/A N/A
Essentially, I need the information from C (and the adjacent info) to match with B or get sorted by the ID numbers in B. The file is huge and I just need to pull/sort it just by a specific set of ID numbers.
Thank you!
EDIT:I tried to use as suggested, the following in a new column. However, I receive the #N/A and #REF error.
=Index(D:Q,Match(B:B, C:C,0)
Provides error: #N/A and #REF!
You can get all the matching data from C-Q using index(array, match()). Just make the match() on B and C.

Resources