Can you create a crosstab table using Excel's new dynamic functions? - excel

I want to create a summary (sum or count) of a list of data based on two columns, showing all the unique items from the first column down the rows, and the unique items from the second columns across the columns, and the sum (or total) for each combination
I can do the sums with multiple formulae, but I'd like to try to do it in one

OK, so I already have an answer which takes just three formulae, one each for the list of unique row and column items, and one to create all the table counts (and sums are easy to do instead)
If my two columns I want to compare are A and B, and I want my crosstab to start in D1 (say)
This formula gives me a unique sorted list of items in column A, down the page
The filter is used to exclude blanks, otherwise Excel will add a 0 at the bottom
D2 = SORT(UNIQUE(FILTER(A:A,A:A<>"")))
This formula gives me the unique sorted items from the second column, transposed to go along the columns
E1 = TRANSPOSE(SORT(UNIQUE(FILTER(B:B,B:B<>""))))
Then this formula goes in E2
E2 = COUNTIFS(A:A,D2#,B:B,E1#)

Related

Dynamic Array Solution for the Product of two Columns in Excel?

How can the product of 2 columns be calculated with a dynamic array solution such that the resulting array automatically resizes for the respective lengths of the 2 input columns?
For example, suppose there are 2 columns (col A and B), and a 3rd column for returning the product of those columns A and B. What I am looking for is a dynamic solution that automatically extends whenever new values are entered into both columns A and B and shows the resulting product of all values row by row.
I want to avoid using macros or dragging of cells for extension of the calculation.
What I have tried is adding the function =PRODUCT(A1,B1) but that does not automatically extend I have to drag the cell down the column.

Excel Expand formulas based on the length of the list results

I'm using the filter formula to return a list of results. The length of rows of the list is variable.
For each returned value I need to apply a new formula. I would like to know if I can extend this formula automatically all rows based on the length of the list.
A simple example: On cells A1:B100 I have a list of values. On Cell D1 I have this formula =FILTER(A2:A10;B2:B10="Filter")
The result will be a list in Colum D that can have 1 row and upto 100.
In Column E I need to have this formula D1*10. This should extend to the rows below dynamicaly based on the number of rows returned on the Filter formula
Any ideas if this can be done automatically?
What I'm doing is quite more complex than this example since I'm filtering a table that is in a different workbook that is custom data type and the number of rows will vary from about 10 to over 9.000
Use the spilled range operator # after the cell in question:
=D1#*10

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)

Text to columns based on unique list and multiple criteria

I have a set of data with multiple columns. I'm trying to transfer the data from columns to rows, but only for the unique members.
For instance, I would like the "Hours Worked" to populate under the correct month in the rows to the right based on unique "SSN"
I've tried =IF($P2=$C2,HLOOKUP(Q$1,$H:$H,MATCH(Q$1,$H:$H,0),FALSE),"")
Index/Match, etc but can't figure it out.
https://docs.google.com/spreadsheets/d/13jJJ0GXb6hFW7YEyyqrCn8cfotUeFurtm0U1EFj_kPY/edit?usp=sharing
Try the following formula in cell F2 and copy it over:
=SUMPRODUCT(--($E2=$A$2:$A$13),--(F$1=$C$2:$C$13),$B$2:$B$13)
The result of ($E2=$A$2:$A$13) is an array containing trues and falses, depending on whether the ID in column E is equal to the ID in column A. (F$1=$C$2:$C$13)does the same thing for the date. By adding -- in front of these arrays, we convert the trues and falses to ones and zeros, respectively. The third array contains the hours worked in each month. These three arrays are then multiplied (and summed up in case there were several entries for one ID in one month).

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