Complicated SUM formula - excel

I'm having a nightmare trying to come up with a formula to solve the following issue. I have two columns 'Record Count' and 'Actual Hours', where record count is greater than 1 I need to sum the data in actual hours. If possible I only want to use one formula and the maximum record count that I can see is 5.
So if you check out the image below, for the rows where the are 5 records I want to see 15.75.
This would be the sum of 1.19, 1.75, 2.31, 3.5 and 7 as these all relate to a single client.
enter image description here

Looks like you want to get total time for each clientid. In that case it does not matter whether there is one or more records for the client. Assuming, clientid is column C and Actual hours column D, in B2 enter =SUMIF(C:C=C2, D:D). Copy all the way down.

Looks like a task for SUMIF():
=SUMIF(A:A,">1",B:B)
(assuming A:A is 'Recoud Count' column and B:B is 'Actual Hours')
This will get you the sum of hours where record cound is more than 1.

Starting from second record you can do partial sums. Here B is record count, C is client ID, D is actual hours. For second line (E2):
=IF(AND(B2>0,C2=C1),E1+D2,IF(C2>0,D2,0))
For A2:
=IF(C3=C2,"",E2)
It uses two formulas, requires to move whole table one row down and only places one entry against each client. If this is works for you - give it a try.
If you don't want to move data you can paste this formula in E2:
=IF(ROW(E2)==1,IF(B2>0,D2,IF(C2>0,D2,0)),IF(AND(B2>0,C2=C1),E1+D2,IF(C2>0,D2,0)))
If the row is first the rows above are ignored (avoiding nullPointerException). If the row is second or below it works does the comparison to see border of userid.

Related

averaging every nth rows and excluding values

I want to average every 5 rows but also to exclude in the average values that are less than 50. This is the command to average every 5 rows.
=AVERAGE(OFFSET($L$3,(ROW()-ROW($P$2))*5,,5))
This is the command to exclude values less than 50
=AVERAGEIF(L3:L8,">50")
How do I combine those two in one command?
Thanks to a colleague of mine, the following works like a gem.
=IFERROR(AVERAGEIF(OFFSET($L$3,(ROW()-ROW($P$2))*5,,5),">50"),0)
As long as you have Excel 2016, a SUMPRODUCT formula will work.
=SUMPRODUCT((MOD(ROW($A$1:$A100),5)=0)*($A$1:$A$100<50)*$A$1:$A$100)/SUMPRODUCT((MOD(ROW($A$1:$A100),5)=0)*($A$1:$A$100<50)*1)
I assumed your data was in A1:A100 so update that as needed. And in the MOD formula, I used 5 for ever 5th row. If you need to change that, change the 5 in MOD formulas. Lastly, the formula does not include the value 50 since you stated you wanted less than 50.
'Tiny' Differences
Correction
=IFERROR(AVERAGEIF(OFFSET(L$3,(ROW()-ROW(L$2))*5,,5),">50"),0)
Visualize
Let's first visualize what you're actually doing.
For every five rows in column L you are displaying the average of the values, if they are greater than or equal to 50. (in this example) in column G:
For L3:L8 in G2,
for L9:L13 in G3,
for L14:L18 in G4 etc.
Issues
The 1st issue is that the formula is written exclusively for the
2nd row. If you want the first result to be displayed in the first row, the formula will result in a REF! error.
If you want to display the first result in the 1st row you have to
change L$2 to L$1:
=IFERROR(AVERAGEIF(OFFSET(L$3,(ROW()-ROW(L$1))*5,,5),">50"),0)
or for the 3rd row you have to change L$2 to L$3:
=IFERROR(AVERAGEIF(OFFSET(L$3,(ROW()-ROW(L$3))*5,,5),">50"),0)
The 2nd issue is that you are doing something in column L and for
no obvious reason you are using column P in your formula. You could
have used any column Z, AN or CG, but your doing stuff in
column L, so use L.
The 3rd issue is that you have locked the columns $L which means where
ever you put the formula in a single row, the result will be the same. If
you don't lock them, you can copy the formula e.g. to the right and
it will display the results for columns M, N, O etc.:
Other Formulas
=SUM(OFFSET(L$3,(ROW()-ROW(L$2))*5,,5))
=COUNT(OFFSET(L$3,(ROW()-ROW(L$2))*5,,5))
=AVERAGE(OFFSET(L$3,(ROW()-ROW(L$2))*5,,5))
=SUMIF(OFFSET(L$3,(ROW()-ROW(L$2))*5,,5),">50")
=COUNTIF(OFFSET(L$3,(ROW()-ROW(L$2))*5,,5),">50")
AVERAGEIF is available in Excel from version 2007, but for older versions the following formula can be used instead:
=IF(COUNTIF(OFFSET(L$3,(ROW()-ROW(L$2))*5,,5),">"&50)=0,0,SUMIF(OFFSET(L$3,(ROW()-ROW(L$2))*5,,5),">"&50)/COUNTIF(OFFSET(L$3,(ROW()-ROW(L$2))*5,,5),">"&50))
It first checks if COUNTIF results in 0. If it does it displays 0, otherwise it divides SUMIF with COUNTIF.

Excel, To find a cell based on its value then find another cell starting the search from the previously found cell position

I have a huge excel sheet that i need to extract some data from...
To simplify what exactly i want to do i'll provide a simple example...
Now allow me to explain what is this and what i am looking to achieve...
In the image the first table to the left contains the following:
B1/B2/B3 which stands for Building 1, 2 and 3
Each building contains 3 floors, F1/F2/F3
Each floor have 3 different tasks that are in progress, T1/T2/T3
In front of each task there are two values V1/V2 which are planned progress and actual progress for the task respectively.
On the right table i want to extract all the values for Task 1 (T1) from the left table for all Buildings and all Floors...
The first thought would be to do a manual extraction by linking each cell on right table with its corespondent on left table, but, with hundreds of buildings and 20th or 30th of floors and 10th of tasks this manual extraction seems like a month work...
The other way is to do that automatically by finding each task and extracting its data to the new table, however there is a huge problem here...
Each similar task is named the same so there are nine T1 and nine T2 and nine T3 in our example. And same goes for the floors there are three of each...
The only thing that is unique are the Buildings B1/B2/B3
So my question is, (explaining what i had in mind):
Is there a way to run a search for lets say in our example B2 (which is Building 2) and once it is found it starts another search from this position (A14) and down looking for 'the first only occurrence' of F2 (which is Floor 2) (so it does not find F2 for Building 3 as well) and once it is found it starts a new search from This B2/F2 position (A19) and down looking for 'the first only occurrence' of T1 (which is Task 1) and then when it is found it extract the numbers in front of it (lets say the one under the second value V2) and place it in the right table which is the Task 1 table (T1) under V2 for B2 in front of F2.
How to achieve that?, what would be the formula or whatever that should be in M5 in our example to get this job done? if it is even possible by a way or another!
Thanks for your help in advance,
Best Regards.
The formula for M5 would be (entered as an array formula using ctrl+shift+enter):
=INDEX($B:$C,MATCH($I$1,IF(ROW($A:$A)>MATCH($I5,IF(ROW($A:$A)>MATCH(IF(M$2="",L$2,M$2),$A:$A,0),$A:$A),0),$A:$A),0),MATCH(M$3,$B$1:$C$1,0))
This can be copied to fill in the rest of the table.
EDIT You can make it faster by limiting it to specific ranges instead of whole columns:
=INDEX($B$1:$C$39,MATCH($I$1,IF(ROW($A$1:$A$39)>MATCH($I5,IF(ROW($A$1:$A$39)>MATCH(IF(M$2="",L$2,M$2),$A$1:$A$39,0),$A$1:$A$39),0),$A$1:$A$39),0),MATCH(M$3,$B$1:$C$1,0))
EDIT2: A quick explanation on the nested MATCH formulas: Start with the third MATCH, MATCH(IF(M$2="",L$2,M$2),$A:$A,0). This finds the row in column A that contains "B2" (14), so the formula becomes.
=INDEX($B:$C,MATCH($I$1,IF(ROW($A:$A)>MATCH($I5,IF(ROW($A:$A)>14,$A:$A),0),$A:$A),0),MATCH(M$3,$B$1:$C$1,0))
The "14" is used in the comparison for the second IF, which will return all the values in column A as an array except the first 14 rows, which will be FALSE in the array. The second MATCH can then find the first instance of "F2" in that array (19). The formula is now:
=INDEX($B:$C,MATCH($I$1,IF(ROW($A:$A)>19,$A:$A),0),MATCH(M$3,$B$1:$C$1,0))
Repeat the same process as before to get the row of the first instance of "T1" after row 19. This is the row fed to INDEX. The last MATCH gives the column for INDEX.

how to group same values into Excel array

I have a duplicate value in column A with different value in column B and column C.
For example:
There are 3 column which is A, B and C.
- A has duplicate value which is serial number
- B is whether it fail the test or not
- C is the time for testing.
Is it possible with Excel to find time difference between time for first fail and pass?
I want to delete the data that have less than 12 hour so that I know the things don't need rework, just retest. I want to know the exact number of modules that need rework.
=IF(AND(B7 = "pass",B6 = "fail", A7 = A6),TEXT(C7-C6, "h:mm"), "")
To get the difference between last fail and pass use this formula in cell D7. If the cell in column B is pass and previous cell was a fail, it will work out the time difference between the previous cell that was a fail. It will also check that the cell in column A matches previous cell in column A. Can also try using Index / Match or Vlookup to get the first fail by formula. As Tim Williams said a pivot table will also help. I don't use them much, so I'm not sure how to get the time difference with a pivot table, but it'll make viewing the data easier.
You could also try adapting this formula, by nesting conditions to get the previous cell that is the first fail. Work out the maximum number of cells between a pass and a first fail, and nest it that many times. If there are cases where the fail time is later than the pass it will throw an error. If you have multiple consecutive pass cells, for the same element you'd need to add more conditions to account for that, but if there's only 1 pass per element this should work.
=IF(AND(B7="pass",B5="fail",A7=A5),TEXT(C7-C5,"h:mm"),IF(AND(B7="pass",B6="fail",A7=A6),TEXT(C7-C6,"h:mm"),""))

Excel: How do I sum cell values every nth colum

I have the following table:
and I'd like to have the total for each player but values are every 3 columns.
As you can see from the picture on the bottom part I wrote what manually I should enter.
For player 1
=SUM(D3;G3;J3...)
Player 2
=SUM(D4;G4;J4...)
and so on. What formula should I use to calculate automatically every 3 columns? I know how the MOD works but on the net I found too many examples each one using different methods and none worked so far. Can anyone help me please or point me to the right direction to understand how it works to get this data since I'll be using this a lot (get value from cell every nth column).
thanks
It looks like you should just be using SUMIFS here:
=SUMIFS(3:3,$2:$2,"TOT")
This will sum every value on row 3 (Player 1) where the value in row 2 is "TOT" (every 3rd column). Put this in cell B18 and just copy down in your column B.
Or, in case you change your column labels, you can refer to cell D2 instead of typing "TOT" in the formula:
=SUMIFS(3:3,$2:$2,$D$2)
Try this, it will total all the cells that occur every 3 columns beginning at column D. Z3 can be increased to any column you require:
=SUMPRODUCT((D3:Z3)*(MOD(COLUMN(D3:Z3)-1,3)=0))
The explanation on how it works can be found here (I advise you to bookmark this site for future references. They have many other helpful formulas and functions).
Applying this formula to your reality should be something like this for Player 1 (Not tested. Adjust the ranges as required):
=SUMPRODUCT(--(MOD(COLUMN(D3:Z3)-COLUMN(D3)+1,3)=0),D3:Z3)

Finding nth Occurrence in multiple columns in Excel

I have two columns with team names and two columns with corresponding stats. I need to go through the 2 columns and find the stats that match the team name, and they need to be in order. VLOOKUP, MATCH, and SEARCH don't seem to work with multiple columns. Does anyone know how this can be done?
Assuming in your picture, the "Home" title is in cell B2 then the following array formula can be put in the cells H3:L7 (array formulas need to be entered with Ctrl+Shift+Enter)
=IFERROR(OFFSET($D$1,-1+SMALL(IF(($B$3:$B$7=H$2)+($C$3:$C$7=H$2),ROW($B$3:$B$7),"X"),ROW()-ROW($2:$2)),--NOT((INDEX($B:$B,SMALL(IF(($B$3:$B$7=H$2)+($C$3:$C$7=H$2),ROW($B$3:$B$7),"X"),ROW()-ROW($2:$2)))=H$2))),"")
Let me break it down...
the logic is: OFFSET(top_of_results,row_number_that_has_Nth_team_score,0_or_1_for_home_or_away)
this is wrapped in an IFERROR in for where there isn't e.g. a 5th score for team A
using the array part IF(($B$3:$B$7=H$2)+($C$3:$C$7=H$2),ROW($B$3:$B$7),"X" we get an array of that has the ROW number if either (done using +) B or C have a value matching our team header (H$2) or an X otherwise
using SMALL(...,ROW()-ROW($2:$2)) we get the Nth smallest row, based on 1st being in row 3, 2nd in row 4 etc.
to get whether it is home or away, we check column B on our row to see if it matches --NOT((INDEX($B:$B,row_number_that_has_Nth_team_score-O)=H$2)) this gives 0 for home, 1 for away and this is used to offset the column
Hopefully it makes sense. Array formulas are very powerful, if a little confusing :-) I recommend CPearson's intro for more information.
Good luck!

Resources