Filtering two columns: keep all the rows associated to one ID if exists a value in the second column - excel

I have a table with various columns but i need to filter it based on two, the table structure is the following:
ID Test
1 A
1 B
1 C
2 B
2 D
3 A
4 A
4 C
4 D
5 B
5 C
What i need to do is keeping all rows associated to one ID if exists the case where the test is "A", the filtered table should then be:
ID Test
1 A
1 B
1 C
3 A
4 A
4 C
4 D
Is there a way to do this?

Alternatively you can use:
=FILTER(A1:B11,COUNTIFS(A1:A11,A1:A11,B1:B11,"A"))
Or, based on your comment:
=LET(X,COUNTIFS(B1:B11,B1:B11,L1:L11,"A"),INDEX(FILTER(B1:L11,X),SEQUENCE(SUM(X)),{1;11}))

If you have Excel365 and access to dynamic formulas then try below-
=FILTER(A1:B11,ISNUMBER(MATCH(A1:A11,UNIQUE(FILTER(A1:A11,B1:B11="A")),0)))

Related

Excel function using value from previous function not working

I'm trying to use the following max function by the group in column A. The value I want in C is the max entry of each group in column B. When column B is normal numbers, this function works. However, I would like column B to be populated by the results of a different function (in this case an =IF function that successfully returns a number). When I do this, I get 0's.
in column C: =MAX(IF($A$2:$A$5=C2,$B$2:$B$5))
Column A
Column B
Column C
Group 1
5
5
Group 1
4
5
Group 2
6
7
Group 2
7
7
Column A
Column B
Column C
Group 1
=IF(...)
0
Group 1
=IF(...)
0
Group 2
=IF(...)
0
Group 2
=IF(...)
0
Any idea what could be going on? Please let me know if I can provide anything additional to help explain.
Thank you!
Reese

for given data i need to find the count of "a" in the column Key

Key
----------
0 a
1 a
2 b
3 b
4 a
5 c
so far i tried this:
df.groupby(["key1"],).count()
However it is also showing the counts of b and c, i want only for a.
Create mask and count by sum:
df["Key"].eq('a').sum()

How can I count the number of values by group in excel

I was wondering if there was a way to count the number of values by category. Example:
A 3
A 3
A 3
B 4
B 4
B 4
B 4
C 5
C 5
C 5
C 5
C 5
D 2
D 2
What is happening there is that there are 5 categories "A, B, C, D" and there are different counts of it. Duplicate values. I would like to create a new column and output the number of times it occurs in a different column as shown above. Please no VBA as i don't know it.
Try this...
=IF(A2<>A1,COUNTIF(A:A,A2),"")

Sum values if multiple conditions met in different sheet

I have one sheet that creates a mapping of names to values (Map_Sheet). In another sheet there are values for each name in the mapping table (Data_Sheet). What I am trying to do is add values based on certain conditions in the mapping table. For example: I want to add all counts of dog by bread and color. So in the mapping table I would look for all dogs that are brown and of a certain bread and get their names and manually add them together. I want to have a formula that does the addition based upon multiple conditions from Map_Sheet.
Here is an example of the data:
Map_Sheet-
name|bread|color|age
a x b 2
b y w 3
c x b 2
d z f 4
Data_Sheet -
id|a|b|c|d
0 3 4 2 1
1 1 2 4 2
2 3 5 7 2
3 1 2 6 9
4 1 3 5 7
And for each ID in the data sheet I want a count of bread X with color B. So I would add for ID0 values for A and C, (3+2) - so ID0 = 5, etc for each id.
I cannot use VBA so I was looking into using INDEX and MATCH but I cannot wrap my head around it. Any ideas? Thanks!
If the row headers in the first sheet match the column headers in the second sheet, you can put this formula in (say) G2 of the second sheet.
=SUM(TRANSPOSE(Map!$C$2:$C$5="b")*C2:F2)
If the column headers in the second sheet were in a different order, you would have to use something like:-
=SUM(C2:F2*NOT(ISERROR(MATCH($C$1:$F$1,IF(Map!$C$2:$C$5="b",Map!$A$2:$A$5),0))))
Both of these are array formulae. You can add extra conditions to select breed as well as colour using the same basic pattern:-
=SUM(TRANSPOSE((Map!$C$2:$C$5="b")*(Map!$B$2:$B$5="x"))*C2:F2)
or
=SUM(C2:F2*NOT(ISERROR(MATCH($C$1:$F$1,IF((Map!$C$2:$C$5="b")*(Map!$B$2:$B$5="x"),Map!$A$2:$A$5),0))))

agregate in vertical 2 or more colums in EXCEL

I'm looking for a way to take these columns (Name/value)..
Name Value Name Value
a 1 c 3
b 2 d 4
and join them together as follows:
Name Value
a 1
b 2
c 3
d 4
Thanks
A PivotTable constructed with multiple consolidation ranges (one for each pair) would achieve the result you want (but might be little easier that copy and paste):

Resources