Excel Count rows where value in Column A has a duplicate in column B and that duplicate's other value in Column A equals something - excel

Given the table below:
A
B
C
D
1
happy
1-veggies
GHF
1
sad
1-veggies
HGF
2
angry
1-veggies
GHG
2
sad
1-veggies
FGH
3
sad
1-veggies
HGF
4
moody
2-meat
FFF
4
sad
2-meat
HGF
5
excited
2-meat
HGF
I need to count the number of rows where C="1-veggies", B="sad", A has a duplicate within A and whose alternative rows in A have a value in D = "GHF" or "FGH".
The result should be 1 based on the second row.
The second row has B= "sad", C = "1-veggies", A has a duplicate within A, whose value is "1" and the 1st row, also with A = "1" has a value in D = "GHF".
I already have a formula as follows:
=SUMPRODUCT((B1:B8="sad")*(COUNTIF(A1:A8,A1:A8)>1)*(C1:C8="1-veggies")*(D1:D8="GHF"))
However, it isn't able to check the 1st row nor does it check the necessary OR statement on column D.
I don't know how to accomplish either task. Thank you.

Add some more COUNTIFS():
=SUMPRODUCT((B1:B8="sad")*(COUNTIF(A1:A8,A1:A8)>1)*(C1:C8="1-veggies")*(COUNTIFS(A1:A8,A1:A8,B1:B8,"<>sad",D1:D8,"GHF")+COUNTIFS(A1:A8,A1:A8,B1:B8,"<>sad",D1:D8,"FGH")>0))

Basically you want to select rows where C="1-veggies", B="sad" and join them to rows where D = "GHF" or "FGH", but with a condition that the value in column A is equal in both but the row number is unequal. This might be a good use of Power Query for users who are expert in this, but using formulas is problematic because of the limitations of countifs (has to be a range). A workaround if you have Excel 365 would be to use some filters followed by countifs:
Column E
=FILTER(A1:A8,(B1:B8="sad")*(C1:C8="1-veggies"))
Coumn F
=FILTER(ROW(A1:A8),(B1:B8="sad")*(C1:C8="1-veggies"))
Column G
=FILTER(A1:A8,(D1:D8="GHF")+(D1:D8="FGH"))
Column H
=FILTER(ROW(A1:A8),(D1:D8="GHF")+(D1:D8="FGH"))
Then
=SUM(COUNTIFS(E1#,G1#,F1#,"<>"&H1#))

Related

How to find and replace from a List in Excel

Not using VBA but just simple excel, can anyone help me find a solution to this problem? Would greatly appreciate it!
I have a list of Names in Sheet 1 like below
-
A
1
sp_abc_Rick
2
sp_abc_Jabba_the
3
sp_abc_Dany
4
sp_random_Rick
5
sp_random_Jabba_the
6
sp_random_Dany
7
sp_constant
8
sp_ripley_art_Dany
9
sp_ripley_art_Jabba_the
10
sp_wakeup
I have a list of Mapping Table in Sheet 2 like below
-
A
B
1
Rick
Morty
2
Jabba_the
Hutt
3
Dany
Dragon
I wish to have a result in Sheet 1, in column B, like below
-
A
B
1
sp_abc_Rick
sp_abc_Morty
2
sp_abc_Jabba_the
sp_abc_Hutt
3
sp_abc_Dany
sp_abc_Dragon
4
sp_random_Rick
sp_random_Morty
5
sp_random_Jabba_the
sp_random_Hutt
6
sp_random_Dany
sp_random_Dragon
7
sp_constant
sp_constant
8
sp_ripley_art_Dany
sp_ripley_art_Dragon
9
sp_ripley_art_Jabba_the
sp_ripley_art_Hutt
10
sp_wakeup
sp_wakeup
To give you a context of the number of rows. Sheet 1 will be bigger with more than 1000 rows. Sheet 2 (Mapping Table) is constant set of rows. Currently it is about 100 rows.
You can use a formula like shown below using LOOKUP(), SEARCH() with SUBSTITUTE()
• Formula used in cell B1
=IFERROR(SUBSTITUTE(A1,LOOKUP(9^9,SEARCH($D$1:$D$3,A1),$D$1:$D$3),
LOOKUP(9^9,SEARCH($D$1:$D$3,A1),$E$1:$E$3)),A1)
There you go. There may have other better solution. This is what I got.
All in column B.
=IFERROR(CONCAT(MID(A1,1,MATCH(1,(CODE(MID(A1,ROW($Z$1:$Z$255),1))<90)*(CODE(MID(A1,ROW($Z$1:$Z$255),1))>=65),FALSE)-1),INDIRECT(CONCAT("sheet2!b", MATCH(MID(A1, MATCH(1,(CODE(MID(A1,ROW($Z$1:$Z$255),1))<90)*(CODE(MID(A1,ROW($Z$1:$Z$255),1))>=65),FALSE), LEN(A1)), Sheet2!$A$1:Sheet2!$A$300, 0)))),A1)
Break down is as follow;
Let's start put things from Column C onward.
Column C, to find the index of the first capital letter from the text.
ref: http://dailydoseofexcel.com/archives/2007/02/21/find-position-of-first-capital-letter-in-a-string/
=MATCH(1,(CODE(MID(A1,ROW($Z$1:$Z$255),1))<90)*(CODE(MID(A1,ROW($Z$1:$Z$255),1))>=65),FALSE)
Column D, cut the name part by using upper case letter index from column C, sp_abc_Jabba_the -> Jabba_the
=MID(A1, C1, LEN(A1))
Column E, search row number from Sheet2 by matching Column D's name with Sheet 2's Column A, this will get matching row number from Sheet2.
=MATCH(D1, Sheet2!$A$1:Sheet2!$A$300, 0)
Column F, get Sheet2's Column B value by the row number from Column E.
=INDIRECT(CONCAT("sheet2!b", E1))
Column G,
Cut "sp_abc_" from "sp_abc_Rick"
Concat "sp_abc_" with Column F's "Morty".
If there is any error, use Column A value as default.
. <- this dot is intentional. please ignore.
=IFERROR(CONCAT(MID(A1,1,C1-1),F1),A1)
Try:
Formula in B1:
=BYROW(A1:A10,LAMBDA(a,LET(b,TEXTBEFORE(a&"|","_"&A12:A14&"|",-1),IFERROR(CONCAT(IF(b&"_"&A12:A14=a,b&"_"&B12:B14,"")),a))))
The concatenation with a "|" would assert we only replace values when at the exact end of the input. Just in case there would be a stray (for example) 'Rick' somewhere before the end.

Excel count rows where column B equals value and value in column A is not a duplicate

I have a table as follows:
A
B
1
happy
1
sad
2
angry
2
sad
3
sad
4
moody
4
thoughtful
5
excited
I need to count the number of times "sad" appears in column B whose value in column A is NOT a duplicate.
I am aware of =COUNTIF(B2:B8, "sad") but I'm stuck there.
Our answer should be 1 since sad only occurs once without a duplicate in A.
Thank you.
Use SuMPRODUCT with a COUNTIFS():
=SUMPRODUCT((B1:B8="Sad")*(COUNTIF(A1:A8,A1:A8)=1))

Ignore text values in subtotal function

Excel-Sheet:
A B C D E
1 1.200
2 Product A 500
3 Product B 400
4 Product C OK
5 Product D #NA
6 Product E 300
7
8
In the above table I have list of products in Column A and some data about the products in Column B.
In Cell B1 I want to calculated the subtotal of Column B using =SUBTOTAL(9,B2:B6).
However, now I have the issue that Column B not only consists of numbers.
It can also have the data type text (OK, NA). Therefore, the result in Cell B1 currently is #NA.
Is there any kind of formula that I could use so only the number data is considered and the result is 1.200 as in the table above?
Please note:
This function =AGGREGATE(9,6,B2:B6) won't help me because I want to filter the list later on so I need to go with the SUBTOTAL.
Use 7 as the second criterion in AGGREGATE instead of 6 as it will also exclude hidden rows:
=AGGREGATE(9,7,B2:B6)
You can solve this, combining the Excel worksheet functions =Value() and =IfERROR():
The function =Value() gives the value of a number, and in case of text it gives an error.
=IfError() can be used to give 0 in that case.
So, imagine you have following situation:
Column A Column B Column C
1 =Value(A1) =IfError(B1;0)
3.5 =Value(A2) =IfError(B2;0)
AB =Value(A3) =IfError(B3;0)
abc10 =Value(A4) =IfError(B4;0)
This gives following results:
Column A Column B Column C
1 1 1
3.5 3.5 3.5
AB #Value 0
abc10 #Value 0
You can simply take the sum of column C.
So this is based on the summary in B1.
=SUM(IF(ISERROR(B2:B6),"",B2:B6))
You need to push Ctrl+Shft+Enter for this to work.
Hope it helps.

Excel if vaules of 2 columns match then take the difference of another two columns

I have 4 columns of data. I want to match the values of two of the columns then if take the difference of two other columns if the first two match. So it's accounts and amounts.
Example. If col A matches Col C take the difference of Col B and Col D and Out it in Col E
Col A Col B Col C Col D Col E
1234 $100 1234 $100 $0
1235 $120 1235 $150 $-30
1236 $150 1237 $150
1238 $130
=IF(A1=B1,C1-D1,)
A1 and B1 are cell references to values you are comparing, and C1 and D1 are cell references to the values you are trying to take the difference of. If you'd like to have the cell be blank instead of 0, add "" after the last comma.
Assuming first data row to be A2:E2, Please put below mentioned formula in cell E2
=IF(A2=C2,B2-D2)
Similarly you can do reverse action by like if it is not then add them or put 0 or blank by "" or subtract B2 from D2 by below given options.
=IF(A2=C2,B2-D2,B2+D2)
=IF(A2=C2,B2-D2,0)
=IF(A2=C2,B2-D2,"")
=IF(A2=C2,B2-D2,D2-B2)
Hope this would help!

Find duplicates with a suffix in excel and keep results

I have a spreadsheet with a list of items in one column (A) and in column C shows the total sold. I'm trying to find all the items within column A.
The issue is, some items are the same, only they have a suffix, mostly separated by a -. The values in column C would be different as well.
Example:
ABC = 5
ABC-123 = 3
ABC-543 = 2
I'm looking to identify only 123 and then combine all the values, so that it will show ABC and 10 as the total.
I've looked around how to remove the duplicate suffix, but have so far failed to find a method when trying to add the total values.
Many thanks
do you mean the data you have looks like this:
column A column B column C
ABC 5
ABC-123 3
ABC-543 2
if so, you can select column A then go to data then text to columns then delimited select other by putting - sign, next and finish.
result must be:
column A column B column C
ABC 5
ABC 123 3
ABC 543 2
then you can =sumifs(C:C;A:A;"ABC") (keep in mind that column B must be empty)
if you have ABC-123 = 3 in the same cell as a text, then you can do:
=IF(SEARCH("ABC";F3);RIGHT(F3;LEN(F3)-FIND("=";F3)-1);"")
where F3 is equal to ABC-123 = 3 The formula above searches fo ABC and gives you a value after = sign, no matter how long this value is. If there is no ABC it will return an error.
if there is no need to look for ABC then just use:
=RIGHT(F3;LEN(F3)-FIND("=";F3)-1)
I hope this helps. I cannot comment, so ask if you have questions.
Best - AB

Resources