how to separate values in a column in excel - excel

I have an excel file with two columns time and output.
output column consist of two values 1 and 2.
I want to make a calculate total time output 2 last in continuity i.e end time -start time.
for example
time output total
2 2 4-2=2
4 2
6 1
8 2 10-8=2
10 2
12 1
14 1
16 1
18 2 22-18=4
20 2
22 2
Is there some easy way to so this as my data file is very large

Try this in C2 and copy down:
=IF(AND(B2=2,B1<>2),INDEX($A2:$A$30000,MATCH(1,$B2:$B$30000,0)-1)-A2,"")
The only caveat is that the last value in column B needs to be a 1. Or it will not do the last calculation correctly.
If you have Excel 2010 or later this formula does not care about the last values in column B. But depending the number of rows it will be slower in the calculations.
=IF(AND(B2=2,B1<>2),INDEX(A:A,AGGREGATE(15,6,ROW(2:$13)/($B2:$B$13 <>2),1)-1)-A2,"")
But it does require that the last row in the specified ranges be at least one larger than the last data row. It can be thousands larger, but that adds calculation times.

Related

Removing several desired rows from excel sheet using the second sheet

How can I remove specific rows which has the same values in another excel sheet? of course there are many columns but I filter such that specific rows remained in the second sheet and we have those values in first sheet as well as other values. for example below I want to delete rows from second set with the same value in the first column of second set. rest does not matter
A B C
1 2 3
4 5 6
7 8 9
10 1 1
second set
A B C
1 5 6
3 3 9
7 7 6
This checks if the value in A2:A4 is in the other sheet in the A-column:
Formula used (I replaced the ´;´ with ´,´)
ISNUMBER(XLOOKUP(A2,Sheet2!$A:$A,Sheet2!$A:$A,"NOPE"))
The only thing left to do is filter by color and delete the rows. Though do remember that deleting rows in larger quantities, if they're not continuous, can be quite slow.

Excel formula - Get the sum of each variable every 6 days

I have the following dataset where I want to get the sum of each variable every 6 days. I can get the total sum of every 6 days using
=SUM(OFFSET($A$2,,(COLUMNS($A$5:A5)-1)*6,,6))
And I can get the total sum of each variable using
=SUMIF(A1:S1,A1,A2:S2)
But I cant get the total sum of each variable within the block of 6 days. It won't increment when I drag the formula.
So the results should be
First batch Second batch Third batch
A B C A B C A B C
2 2 2 4 4 4 6 6 6
You can use SUMPRODUCT:
=SUMPRODUCT((1:1=A6)*2:2*(COLUMN(1:1)>(INT((COLUMN()-1)/3)*6))*(COLUMN(1:1)<=(INT((COLUMN()-1)/3+1)*6)))
Edit:
To shift the column by five position, you will need to change the following parameters in the formula:
Full row range change to exact range, i.e. 1:1 to e.g. $F$1:$W$1
Change COLUMN()-1 to COLUMN()-3
If you also want to change the number of columns to be summed, additionally replace the factor of 6 with a 7-1 for seven columns or 36-30 for thirty-six columns.
So formulas looks like:
batch of 6 cols
=SUMPRODUCT(($F$1:$W$1=F6)*$F$2:$W$2*(COLUMN($F$1:$W$1)>=((INT((COLUMN()-3)/3))*6))*(COLUMN($F$1:$W$1)<((INT((COLUMN()-3)/3+1))*6)))
batch of 7 cols
=SUMPRODUCT(($F$1:$Z$1=F6)*$F$2:$Z$2*(COLUMN($F$1:$Z$1)>=((INT((COLUMN()-3)/3))*7-1))*(COLUMN($F$1:$Z$1)<((INT((COLUMN()-3)/3+1))*7-1)))
batch of 36 cols
=SUMPRODUCT(($F$1:$WW$1=F6)*$F$2:$WW$2*(COLUMN($F$1:$WW$1)>=((INT((COLUMN()-3)/3))*36-30))*(COLUMN($F$1:$WW$1)<((INT((COLUMN()-3)/3+1))*36-30)))
Instead of creating a really, really, really complex formula that can be dragged right, I suggest you add a row to the data at the top that identifies the batch number. Then you can use that batch number as an additional parameter in the Sumifs(). you can hide the rows with the batch numbers if they upset your spreadsheet design.
=SUMIFS(3:3,1:1,A16,2:2,A17)
This is far easier than creating a formula that dynamically adjusts references in tiered steps of three and six.

How to get max value in the column whilst counting and then reset count after reaching 0 and start to count until other max value is reached

I am trying to get the max value per run from my table. Each run lasts a different amount of days hence there will be a different max value for each run. My current table column Days looks like this:
Days:
1
2
3
4
5
6
7
8
0
1
2
3
4
5
0
1
2
3
4
5
6
7
8
9
10
11
0
1
2
3
I have another column called Max Day, where I want to get the max day per run from the above Days column, this is the output that I want to get at the end:
Max Days:
8
5
11
3
I have tried doing:
=COUNTIF(A$1:A1, A1) but that doesn't do anything, it just returns 0. Is there a way I can get the max value and then when it reaches 0, it starts counting again and retrieves the max value for that count and then repeat.
If you have Office 365, this is a piece of cake with the new Filter() function. In the screenshot, the formula has been entered into cell C2 and has NOT been copied down. It does that automatically.
=FILTER(A2:A31,A3:A32=0)
Edit - Explanation. For a general understanding of the new Excel Dynamic Array functions, please refer to this blog by the Excel team.
The Filter function returns all rows that match a given criterion. In this case the range to be filtered and the range in the criterion are offset by one row. The filter looks at rows 2 to 31, but the comparison looks at rows 3 to 32.
The effect is that the filter returns a value when the comparison is TRUE for the NEXT row, not the current row. Hence, the function returns all rows where the row FOLLOWING the current cell contains a zero.

Dynamically change row number in excel

I got a file in excel that often changes the row number (My first column) whenever there is a insertion of data. However, there is multiple rows of data with the same row number.
Example:
1
1
2
3
3
3
Is there a way I can change them dynamically beside grouping the number together via Filter and change it manually?
Edited.
1
1
1
2
3
4
4
4
Better example. Sorry about the indentation.
I can propose a partial solution.
Set the value only in the first identical value and change only those unique values when a group of rows is inserted:
1 1
1 =A1
1 =A2
2 2
3 3
4 4
4 =A6
4 =A7
Otherwise, you do it from VBA to change all values when a new row is inserted.

Find maximum of row, return column name

I have four rows and six columns of random numbers between 1 and 10. The headers atop are named A through F accordingly. I want to populate a range (A1:A6) on another sheet with the maximum number for each row. That is easy with the MAX function. However, in a another range (B1:B6), I want to put the column name to which this number belongs.
An HLOOKUP() won't work because a maximum value in one row is likely not unique number across the entire sheet. I am thinking a MATCH INDEX type function, but my understanding of those functions, especially in conjunction, is poor.
A B C D E F
1 0 2 10 9 8
9 3 7 6 9 10
10 3 0 2 1 4
9 4 7 8 6 3
Assuming your array is in Sheet1 and the columns are labelled, please try in another sheet, copied down to suit (to Row4 since there are only four rows of numbers in your data):
=INDEX(Sheet1!A$1:F$1,MATCH(MAX(Sheet1!A2:F2),Sheet1!A2:F2,0))
This will return only the first column label from a row where the maximum for that row occurs more than once.

Resources