Excel: How to sumif, if the data points share the same row? - excel-formula

How can I look up the column header and output the sum of values underneath the two columns but only if they share the same row. For example in my picture I want to sum under A and C which should output 2 since they share a 1 in both the top row and the bottom row. Again if I wanted the same formula for A and B it would output 0 as they share none of the same data points in the same row. Basically I want to pivot not numerical data and be able to determine the total number of shared x values between my choice of y values.

Use SUMRPODUCT to count where the ranges returned by INDEX/MATCH are equal:
=SUMPRODUCT((INDEX($A$2:$D$6,0,MATCH($F$2,$A$1:$D$1,0))<> "") *(INDEX($A$2:$D$6,0,MATCH($F$2,$A$1:$D$1,0))=INDEX($A$2:$D$6,0,MATCH($F$3,$A$1:$D$1,0))))

Related

Excel: Count the symbol for each merged cells with different size

I have a table as per below. I want to count column C "Count game win" using a formula. each person plays a different round of game within 24 hours and if he/she wins, it is label as Y. I would like to count Y using a formula but column A in merged cells contains different rows. My formula is column C is
=IF(A2="","",COUNTIF(B2:B3,"Y"))
However, when I drag down or copied to other cells, the data is wrong due to uneven size in merged cells in column A. I have a long list and will be unable to count manually. please advice

If X then look for Y in same row (Excel)

Sample spreadsheet
Looking to find out how many times each name appears in right 4 columns depending on the W/L column. Example output I am looking for is a count of times Mozzie appears in any of the four right side columns where there is a W in the W/L Column
Use below formula. Adjust ranges for you sheet.
=SUMPRODUCT((B3:B16="W")*(E3:F16="Mozzie"))

Distinct count of values in a column if two other cells match

Struggling a bit with array formula's to count distinct values in one column, in the rows where two other cells match. Sorry if I can't explain any better. Best is to show you the formula I created and provide some sample data:
Sheet 1
Column A Column B
Period 101 Code X
Period 309 Code Y
Period 101 Code Y
Period 101 Code Z
Period 404 Code Y
Period 101 Code X
Period 101 Code X
Period 404 Code X
Period 404 Code Z
Sheet 2
Column A Column B (where the formula should be)
Code X 2
Code Y 3
Code Z 2
Basically I want to count the distinct values in Sheet 1 column A, only where the value in Sheet 1 column B matches the value in sheet 2 column A. I have provided the expected outcome for the three code values.
I have tried with the following formula, but I am unable to count distinct values in another column where the two cells match:
{=SUM(--(FREQUENCY(IF(C5:C11=G5,MATCH(B5:B11,B5:B11,0)),ROW(B5:B11)-ROW(B5)+1)>0))}
Please ignore the rows and columns used in the formula, also the values in Column A and B on sheet 1 both occur multiple times, but the values in column one on sheet 2 only occur once.
I am curious how someone would solve this one. Thank you in advance.
Caveat: This answer is unlikely to be useful to the OP, as these techniques are as yet only available to Excel Insiders
But once these new features are available to the main stream they will be a game changer.
This uses the new Dynamic Array feature coming to Excel soon.
To create the list of unique values from Column B, place this formula in a single cell. Excel will "Spill" into as many rows as needed to return the unique list of values from Column B. For example, I have used cell E2
=UNIQUE(FILTER($B:$B,$B:$B<>""))
Now, place this formula in a the next adjacent cell, I've used F2
=COUNTA(UNIQUE(FILTER($A:$A,$B:$B=$E$2)))
Again, you only need to put this formula in one cell, no need to copy down. Excel will "Spill" the result into as many cells as needed, to match column E.
Your formula doesn't match your sample data but let's assume the below:
Formula in H5:
=SUM(--(FREQUENCY(IF(C$5:C$13=G5,MATCH(B$5:B$13,B$5:B$13,0)),ROW(B$5:B$13)-ROW(B$5)+1)>0))
Entered as array through CtrlShiftEnter and drag down
Notice the semi-absolute cell references (you used relative ones) + how my ranges are larger than yours (you looked from C5:C11 only)

Excel formula to calculate the sum of the first n% visible rows in a filtered column

As I stated in the title, I want to calculate the sum of the first n% rows in a filtered column. The total numbers of rows in the column varies due to the filtering options, so my formula must work with different values of n.
For example :
In column A, I have 10 rows that contain values from 10 to 1 ( I sorted them from largest to smallest ).
In column B, I have 10 corresponding rows that contain 2 names: 4 of them contain the value "Tom", six of them contain the value "Jerry". When I filter the whole table and select only the rows that contain the value "Jerry", I want to be able to calculate the sum of the first 20% of the corresponding 6 number values.
This could work without any filtering if you want.
With criteria for column B in E1 and percentage you looking for in F1 with the assumption we want to round up the percentage to integers.
So formula in D1:
=SUMPRODUCT(LARGE((B2:B11=E1)*(A2:A11),ROW(A1:INDEX($A:$A,ROUNDUP(COUNTIF(B2:B11,E1)*F1,0)))))
So, without your data, I came up with this, edit to suit your situation...
So, based on the comment, I did a second version:
The helper column in col C is used with sumproduct to give the result...
You can use the percentile function in AGGREGATE with SUMIFS to do what you want:
=SUMIFS(A:A,B:B,"Jerry",A:A,">="&AGGREGATE(16,7,A1:A10/(B1:B10="Jerry"),0.8))
If you want to use the filter to do the decision:
=SUMPRODUCT(SUBTOTAL(3,OFFSET(A1,ROW(A2:A10)-1,,1))*(A2:A10>=AGGREGATE(16,7,A2:A10,0.8)),A2:A10)

How to get the highest values from 2 columns in Excel?

I have a design software which extracts data in to an Excel sheet format
The output is divided into 2 columns, each of these columns has more than 1000 rows.
To make use of this data I need to summarize it to a maximum of the 5 highest values from both of the 2 columns. Therefore, this doesn't mean that it's the maximum of one column and its corresponding value, but it may mean that the 2nd largest value of column 1 & the 4th largest value of column 2.
For example ( if we quoted some of the output data):
The values i should pick here are:
If there is any possible way to achieve that, it will be great
Thanks ..
example file: http://goo.gl/UIEFEv
example file 2: http://goo.gl/VSvuVf
Here's a formula solution. I used 20 rows and extracted the rows which contain the top 5 for each column - you can extend to as many rows as required.
With data in A1:B20 use this formula in D1 confirmed with CTRL+SHIFT+ENTER and copied across to E1 and down both columns:
=IFERROR(INDEX(A$1:A$20,SMALL(IF(($A$1:$A$20>=LARGE($A$1:$A$20,5))+($B$1:$B$20>=LARGE($B$1:$B$20,5)),ROW(A$1:A$20)-ROW(A$1)+1),ROWS(D$1:D1))),"")
Note: there are only eight rows extracted because some of the rows contain values in the top 5 for both columns. I added the highlighting in colums A and B to more clearly illustrate
see screenshot below
Edit:
From the comments below it seems that you want a combination of rows which contain the highest value for that column....and rows which contain the highest total for both columns.
In the original formula there are two conditions joined with "+", i.e.
($A$1:$A$20>=LARGE($A$1:$A$20,5))+($B$1:$B$20>=LARGE($B$1:$B$20,5)
The "+" gives you an "OR" type functionality, e.g. in this case rows are included if individual values are in the top 5 in that particular column. You can add other conditions, so if you want to also add any rows which are in the top 5 considering the total of both columns then you can add another "clause", i.e.
($A$1:$A$20>=LARGE($A$1:$A$20,5))+($B$1:$B$20>=LARGE($B$1:$B$20,5)+($A$1:$A$20+$B$1:$B$20>=LARGE($A$1:$A$20+$B$1:$B$20,5))
....and including that in the complete formula you get this version:
=IFERROR(INDEX(A$1:A$20,SMALL(IF(($A$1:$A$20>=LARGE($A$1:$A$20,5))+($B$1:$B$20>=LARGE($B$1:$B$20,5))+($A$1:$A$20+$B$1:$B$20>=LARGE($A$1:$A$20+$B$1:$B$20,5)),ROW(A$1:A$20)-ROW(A$1)+1),ROWS(D$1:D1))),"")
You could refine that further by using combinations of + and * (for AND), e.g. for the new condition you might only want to include rows with a total in the top 5 if one of the single values is in the top 10 for that column...
Explanation:
The above part shows how you can use + for the OR conditions. In the formula if those conditions are TRUE then the IF function returns the "relative row number" of the range (using ROW(A$1:A$20)-ROW(A$1)+1).
SMALL function then extracts the kth smallest value, k being defined by ROWS(D$1:D1) which starts at 1 in D1 (or E1) and increments by 1 each row.
INDEX function then takes the actual value from that row.
When you run out of qualifying rows SMALL function will return a #NUM! error which IFERROR here converts to a blank
The question is a little unclear but if what you mean is to get the 5 highest values of Column A and their corresponding values in Column B then the five highest values in Column B and the corresponding values in Column A then the (non automated) solution is pretty simple.
Click on a cell with a header title in it.
Click on 'Data' in the top menu.
Click on 'Filter' in the 'Sort & Filter' section.
Click on the button on Column A - select 'Sort Largest to Smallest'
Grab the top five values from both columns then click on the button in column B and repeat.

Resources