Cell locations changing with filtered data - excel

So I have some data that is being filtered. I only have a dollar value and a % of total. I am using the filters to sort the data from largest to smallest in regards to the % of Total value.
Below the data set I have a total spend calculation and then I have a Pass Through formula. The Pass Through function is the Subtotal minus a few line items.
My problem is that Pass Through function reads something like =SUM(A1:A10)-A3-A5. When I sort the data then the cells themselves move but my formula doesn't adjust. The amount changes and is now wrong.
Is there anyway so that my formula "follows" the amounts so that it's always correct no matter what sorting I do?

The quickest way is to add a "helper" column of 0's and 1's to your table and use SUMPRODUCT. Here is an example where Cell A11 contains your formula =SUM(A2:A10)-A3-A5 and Cell C11 contains a modified formula =SUMPRODUCT(A2:A10,C2:C10)
Without sorting ...
Sorted ascending ...
Of course, with more complex formula, it can be more complicated to perform.

Related

Copy the Excel RANK formula without changing the end reference

Suppose I have a simple spreadsheet with 3 rows of data that I want to rank in separate columns. The example I will use is simple, but my actual dataset is 12k + rows. In this simple example, I want to use the RANK formula from Excel to do this. To rank the values in column Police, I'll use the formula =RANK(B2, B2:B11, 1), with B2:B11 being the range.
As I mentioned, my actual dataset has thousands of rows and many more columns to compare. Even in this example, I want a simple way to copy the formula to all of the other _RANK column cells. If I simply copy the cell to the other cells, +1 gets added to the cell value. This is what I want to happen, EXCEPT for the ending cell of the range.
As you can see above, this is incorrect. The formula gets set to =RANK(B11,B11:B20,1) for cell E11, when what I want is =RANK(B11,B11:B11,1). How can I easily copy this formula across multiple cells so that it is has the correct formula?
Placing $ before the cell references makes it static. Try changing your formula to Rank(B11, B$2:B$20,1). Coping this formula will only change those references which are not proceeded with $.

Make a list of values in one column, which do not exist in a second column

I have a worksheet with two columns of data. Column A contains thousands of records, and Column B contains only a few records. I wish to identify which values in Column B do not exist in Column A, and display these in Column D. What is the quickest way to achieve this? Happy to use formulas, or otherwise.
I would use conditional formatting and filters:
Formula being:
=ISERROR(MATCH(A1,B:B,0))
I'd then filter on highlighted cells, select the cells in column A and use Alt+; to select only the visible cells, then paste in D.
Last, I'd clear all the conditional formatting and clean up anything left.
Using formulae would be a little more complex; usually the most of the time would be spent designing it, and it's an array formula (invoked correctly only with Ctrl+Shift+Enter):
=IFERROR(INDEX($A$1:$A$27,SMALL(IF(COUNTIF($B$2:$B$6,$A$2:$A$27)=0,ROW($A$2:$A$27),9^99),ROW(D1))),"")
The formula can also take some time to calculate for larger datasets.

Sum values based on first occurrence of other column using excel formula with Subtotal function

I already viewed the posting about summing values based on first occurrence in another cell but I would like to add a complication and nestle in a subtotal function. Basically I would like to sum values in the Score column based upon the first and only instance of a value in Color with subtotal filtering via one formula.
There are two formulas that somewhat give me the two components required but I'm limited in my formulaic abilities to combine these:
Sum values based on first occurrence in another column:
=SUMPRODUCT(B2:B8/COUNTIF(A2:A8,A2:A8))
Subtotal with sumproduct:
=SUMPRODUCT(B2:B8,SUBTOTAL(9,OFFSET(C2:C8,ROW(C2:C8)-MIN(ROW(C2:C8)),0,1)))
Unfiltered Table
Filtered Table
Any ideas?
Many thanks in advance
You can combine both formulas as below:
=SUMPRODUCT(B2:B8/COUNTIF(A2:A8,A2:A8),SUBTOTAL(3,OFFSET(A2:A8,ROW(A2:A8)-MIN(ROW(A2:A8)),0,1)))
The first part of the above formula is from your SUMPRODUCT formula so it is easy to understand, the second part of the formula should be using 3 - COUNT for the SUBTOTAL formula so it will return 1 for values showing in the filtered range and 0 for values that are not.
Let me know if you have any questions. Cheers :)

Count values in column ignoring duplicates

Not really an Excel user, but what seemed simple has turned out to be very difficult for me. I am in trouble as I can't come up with a nice and clean (or any) way to get it working.
What I have here:
I need to create a new columnn that would tell the amount of employees in each occupation while ignoring the duplicates (highlighted).
The amount of names formula is working, so maybe this can be used ? Or maybe it's just in the way and should be cleared.
It's just:
=COUNTIFS(A:A;A2)
Tried searching for quite a while did not find anything suitable. Any help or advice would be much appreciated. I hope I explained it in clear manner.
Thank you
Without helper columns:
Two options, D2:
{=SUM(--(FREQUENCY(IF($B$2:$B$9=C2,MATCH($A$2:$A$9,$A$2:$A$9,0)),ROW($A$2:$A$9)-ROW($D$1)+1)>0))}
Or put in E2:
{=SUMPRODUCT((($B$2:$B$9=C2))/COUNTIFS($B$2:$B$9,$B$2:$B$9&"",$A$2:$A$9,$A$2:$A$9&""))}
Notice both are array formulas and should be entered through CtrlShiftEnter
SUMPRODUCT 'Deals' in Arrays 3
You might have employees with the same name (David, Michael) in different occupations (Tech & Worker, Tech & Economy). To distinguish those from each other, in B2 you can use:
=SUMPRODUCT((A$2:A$21=A2)*(C$2:C$21=C2))
In D2 you can use:
=SUMPRODUCT((1/B$2:B$21)*(C$2:C$21=C2))
Distinct Employees Occupation Count
with a helper column
Unique and Distinct values are tricky. Using a helper column is beneficial for identifying either one of these when coupled with an expanding range:
=SUMPRODUCT((A2=$A$1:$A1)*(C2=$C$1:$C1))
Relative Rows: ^ ^
Paste to cell E2.
Copy Drag the formula down from the where pasted.
The relative row numbers identified above well increase as the formula is copy dragged down. This creates a larger and larger range for comparison. An expanding range.
In this case the range that is expanding is the range of already checked values. Many times the result range is expanded and tested against to eliminate posting duplicates of already posted results in subsequent rows of the results list.
The helper column's value is how many times the name and occupation pair has previously appeared. Zero previous appearances tells us this is the first occurance. We will only count the zeros (first occurance) in the main formula.
The main formula for counting distinct employees in each occupation:
=COUNTIFS( $C$2:$C$9, C2, $E$2:$E$9, 0)
Paste to cell D2.
Copy Drag the formula down from the where pasted.
Here we count all the rows for this row's occupation where the occupation matches the range of listed occupations and for that particular row in the list of occupations, the helper column row value is zero.
Add a final column which is the concatenation of the prior 3 columns then use
=SUMPRODUCT(1/COUNTIF(D2:D9,D2:D9))
There is a good explanation of this formula here. Basically, values that appear once will count as 1. Values that appear more than once will appear as fractions of their total occurrence count and be summed to 1.
If you convert your data to an Excel table by selecting a populated cell in the range and pressing Ctrl+T, then formulas will auto-populate down last column. You can then reference the table columns in the formula and you won't need to amend the formula as you add rows.

Need excel average formula for a dynamic range

This is what my table looks like:
Please note that I cannot change the position of any data here. This is a table that will continuously expand as I add new columns to the right and new rows at the bottom.
I need a formula in Column A that will calculate the average of all data in the same row as where the formula is and the formula has to autoupdate whenever I add new columns to the right of the last column. For example, in cell A64 is the formula that will average C64 to E64. when I add new data in F64, I want A64 to autoupdate to include that new cell in the computation.
I tried
=AVERAGE(INDIRECT("C64:"&ADDRESS(ROW(),COLUMN()+4)))
but it did not autoupdate when I added new data in F64. I am not an excel expert and I mostly learn by googling, but this one is taking me forever. Please help.
This is where OFFSET and COUNTA are your friends, In A2 and fill down:
=AGGREGATE(1,6,OFFSET(C2,,,1,COUNTA(C2:XFD2)))
I have used AGGREGATE function with argument 1 for Average and argument 6 to ignore error values in the range. COUNTA resizes the array from C2 to the end of the populated area (allowing for error values).
You can also use INDEX with COUNTA
=AGGREGATE(1,6,$C$2:INDEX(C2:XFD2,COUNTA(C2:XFD2)))
Or INDEX with MATCH. In the example below, I have reduced the column end point to AA, rather than XFD (which is the last column in 2016). If you know a realistic number of columns that will ever be filled you can use that as your end point reference to reduce the amount of work your dynamic formulas are doing.
=AGGREGATE(1,6,$C$2:INDEX(C2:AA2,MATCH(99^99,2:2)))

Resources