Last Status By Date and Count - excel

I want to extract the last status of a item by date from the sample data given below:
http://i.stack.imgur.com/T4I5W.png
I want the following result:
http://i.stack.imgur.com/xDF55.png
Can this be achieved using a formula or PivotTables?

With pivot table you can easily extract the max date of each item. But the status will be problematic.
So, the best way to do it, is not with a pivot table. but with 3 steps.
1) copy your item list to another sheet to the first column. (I will assume the your first sheet is Sheet1 and the 2nd is Sheet2) choose the entire column in the 2nd sheet and remove duplicates. (date ribbon -> remove duplicates)
2) find your max data for each item.
lets assume your first rows is header so in the 2nd rows on column b enter:
=max(if(Sheet1!b:b=b3,Sheet1!a:a,""))
Note that this an array formula so you have to enter this using ctrl+shift+enter
Now drag this formula to the end of rows
3) find the last status of each item
you have to do double lookup formula
on c2 enter:
=index(Sheet1!c:c,match(a2&b2,Sheet1!b:b&Sheet1!a:a,0),1)
Again, that this an array formula so you have to enter this using ctrl+shift+enter
And again, drag this formula to the end of rows.

Actually this can be done only with formulas and without copying the data in another worksheet.
Assuming your data is in the range A1:C16 (change as needed) then you can enter the following Array Formulas (press [Ctrl]+Shift]+[Enter] together):
Enter "Item" in E1 and this array formula in E2 then copy down till last record (E16 for this sample)
=IFERROR(INDEX($B$2:$B$16,MATCH(0,COUNTIF(E$1:E1,$B$2:$B$16),0)*1),"")
Enter "Date” in F1 and this array formula in F2 then copy down till last record (F16 for this sample)
=IF($E2="","",MAX(IF($B$2:$B$16=E2,$A$2:$A$16,"")))
Finally Enter “Status” in G1 and this array formula in G2 then copy down till last record (G16 for this sample)
=IF($E2="","",INDEX($C$2:$C$16,MATCH($E2&$F2,$B$2:$B$16&$A$2:$A$16,0),1))
Ranges within the formulas should be adjusted as needed, no need to point to all rows in the worksheet.

Related

Cumulative Amounts of Dupe-only Items in a Resultant Sheet

Sheet 1 goes like this:
Sheet 2 should be like this:
ITEMS QUANTITIES
APPLE 4
GUAVA 2
Sorry for writing the spreadsheet in here, as I'm not allowed to include more than 1 image yet.
Suppose you have the following named ranges:
ITEMS being the data in ITEMS column on your Sheet1;
QUANTITY being the data in QUANTITY column on your Sheet1.
Enter the following formula in Cell D2 on your Sheet2:
=IFERROR(INDEX(ITEMS,MATCH(0,COUNTIF($D$1:D1,ITEMS),0)),"")
Please note it is an array formula which requires you to press Ctrl+Shift+Enter upon finishing the formula in the formula bar.
Drag it down until there is no more items showing up.
Then you can enter the following formula in Cell E2 on your Sheet2 and drag it down:
=SUMIF(ITEMS,D2,QUANTITY)
As you can see from the above screenshot, there may be some empty cells in Column D as I used IFERROR to return blank cells if there is no more distinct item. The corresponding quantity will be 0 consequently. You can choose to delete them or hide them on your worksheet.
By the way I am not sure why Pivot Table is out of the picture as it is actually a faster and easier approach than formula and you do not have to worry about the blank cells returned by the formula if the number of unique items is uncertain. All you need to do is to highlight the source data, insert a pivot table, and put the ITEM in Rows and QUANTITY in Values field.
EDIT: Update to also extract unique distinct values:
Enter this formula in cell A2 of Sheet2:
=IFERROR(LOOKUP(2,1/(COUNTIF($A$1:A1,Sheet1!$A$2:$A$300)=0),Sheet1!$A$2:$A$300), "")
Change 300 to the actual last row of your data and copy that formula down until it returns empty cells.
Then just use a regular SUMIF in cell B2 of Sheet2:
=SUMIF(Sheet1!A2:A300, A2, Sheet1!B2:B10)
Then, type whatever fruit you're looking for incell A2 of Sheet2. Continue like this in the following rows for all the fruits you need.

Identify minimum and maximum values based on 3 criteria

In the table shown, I need a formula for column D that will indicate the first date (minimum) and most recent date (maximum) that each participant (in column A) took survey A (in column C). Column D would need to indicate "first" and "last" tied to the Participant ID--for example, I would want D2 to populate with "3Last" and D5 to populate with "3First." Column E displays what I would need column D to display. If it's not a first or last date (something in between), or if it's not survey A, the cell in column D would be left blank or 0. If there is only one date that meets the criteria, it should return "First" rather than "Last." I'm pretty stumped on this one... Any help is much appreciated!
In E2, insert the ARRAY formula listed below. If you have never used an array formula, follow these steps:
select the formula from this page
copy it
go to excel
select cell E2,
press the 'F2' key
paste the formula
press CTRL+SHIFT+Enter (instead of just pressing enter)
To copy down, follow these steps:
Copy cell E2
Move down to cell E3 (instead of selecting a range)
Paste in cell E3
Select your range and paste from there.
If you don't copy down in this manner, it will tell you that you cannot change the array...
=IF($C2="A",IF($B2=MIN(IF(($C$2:$C$7=$C2)*($A$2:$A$7=$A2),$B$2:$B$7)),CONCATENATE($A2,"Last"),IF($B2=MAX(IF(($C$2:$C$7=$C2)*($A$2:$A$7=$A2),$B$2:$B$7)),CONCATENATE($A2,"First"))),0)
HTH

transpose table dynamically in excel

I need some advice for the following task, I have an Excel sheet with 2 columns RESPONSIBLE and SERVICE (see Sheet1 of Attached file )
I need to create on another Excel sheet the matrix as Sheet2 in attached file.
Use the following array formula in B2 and drag/copy as required:
=IF(AND($A2<>"",B$1<>"")=TRUE,IF(ISNUMBER(MATCH($A2&B$1,Sheet1!$A:$A&Sheet1!$B:$B,0))=TRUE,"x",""),"")
To populate the column headers use the following array formula in B1 and drag/copy:
=IFERROR(INDEX(Sheet1!$B$2:$B$100,MATCH(0,COUNTIF($A$1:A1,Sheet1!$B$2:$B$100),0)),"")
To populate the row headers use the following array formula in A2 and drag/copy:
=IFERROR(INDEX(Sheet1!$A$2:$A$100,MATCH(0,COUNTIF($A$1:A1,Sheet1!$A$2:$A$100),0)),"")
Enter all the above formulas with ctrl + shift + enter
I tested the above formulas by increasing the data and it slowed down my excel file. The reason is most likely the first formula.
If you add a helper column in sheet1 then you can add this in C2 (not an array formula):
=A2&B2
Then in sheet2, B2 you can use (not an array formula):
=IF(ISNUMBER(MATCH($A2&B$1,Sheet1!$C:$C,0))=TRUE,"x","")
This will substantially increase the speed to normal levels as the number of array formulas in the sheet are materially reduced.
Or
You can simply use a pivot table. Enter "Service" as column label and value, and "Responsible" as row label. The value should show count of service. The only difference will be that instead of "x" it will show a 1. You will also have to refresh the pivot table whenever you update the data.

Excel function that copies rows if they fall within the range of 2 dates

So at the top of my Excel sheet I have 2 cells, A2 and B2, where people can enter a starting and ending date.
On a seperate sheet I have an enormous list of starting and ending dates in columns A and B, and corresponding data for each of these 'events' in columns D through G. I need my function to copy all rows where the starting date falls between the two specified dates, and copy the data to the first sheet, in cells A4 - G4 through A100 - G100. (I just chose 100 as a large number, to make sure the area where the data gets placed is large enough)
I'm guessing this function I need includes the INDEX function, but I only know how to use it to look up one data cell at a time, not how to copy an entire range of cells.
Can anyone help?
No helper columns required.
Enter this formula into cell A4:
=IFERROR(INDEX(data!D$2:D$9999,SMALL(IF((data!$A$2:$A$9999>=$A$2)*(data!$A$2:$A$9999<=$B$2),ROW(data!$D$2:$D$9999),9E+99),ROW(1:1))-1),"")
This is an array formula and must be confirmed with Ctrl+Shift+Enter.
Now copy the formula to the range B4:D4.
Now copy the A4:D4 to the range A5:D100.
That's it.
Let's say Column C in the data sheet is blank, and free to add a formula.
Let's also assume that the data begins in row 2.
Then the following formula can be put in C2 & copied down:
=IF(AND(A2>=Sheet1!$A$2,B2<=Sheet1!$B$2),C1+1,C1)
Basically it is saying that if the beginning date of the current record is greater than or equal to the date the user is looking for, and the ending date is likewise within range, iterate the record, otherwise not.
At this point the user sheet can have a simple VlookUp as follows:
In D1: =VLOOKUP(ROW($A1),Sheet2!$C:$G,COLUMN(B$1),0)
Copy this across to G and down however many rows you like.

Series based on row and column combination

I have an Excel with rows and columns as below:
I need to build a series like below in Excel with two columns as shown:
I have a huge data set where rows are dates and columns are data in half hours.
Which would be the best method?
I would suggest using the INDIRECT function thus:
In the column when you want to have the Row labels, put this formula:
=INDIRECT("R" & MOD(ROW()-1, COUNTA(A:A))+2 & "C1",FALSE)
Here A:A refers to the column where your row labels are stored and +2 is offset to the first row with a label.
In the column where you want the Column labels, put:
=INDIRECT("R1C" & ROUNDDOWN((ROW()-1)/COUNTA($B$1:$D$1),0)+2,FALSE)
Here $B$1:$D$1 refers to the range with your column labels, and +2 is again offset to the first column label.
Assuming your data is in the range C7:F12
We’ll need three fields to show the resulting series: Row, Col and Data
Row: in cell H7 enter this formula and copy till the last record:
=IF(EXACT(H6,H$6),1,
IF(EXACT($I7,CHAR(133)),"",
IF($I7=1,SUM(1,H6),H6)))
Col: in cell I7 enter this formula and copy till the last record:
=IF(EXACT(I6,I$6),1,
IF(EXACT(I6,CHAR(133)),CHAR(133),
IF(I6=COLUMNS($C$7:$F$12),
IF(H6=ROWS($C$7:$F$12),CHAR(133),1),
SUM(1,I6))))
Data: in cell J7 enter this formula and copy till the last record:
=IF(EXACT($I7,CHAR(133)),"",
INDEX($C$7:$F$12,$H7,$I7))
The following will produce your results but the array formula will impact calculation lag depending upon the number of rows and column of data in the original data matrix.
    
The array formula¹ in A10 is,
=IFERROR(INDEX(A$2:A$6, MATCH(0, IF(COUNTIF(A$9:A9, A$2:A$6&"")<COUNT($1:$1), 0, 1), 0)), "")
The standard formula in B10 is,
=IF(LEN(A10), INDEX($B$1:INDEX($1:$1, MATCH(1E+99,$1:$1 )), , COUNTIF(A$10:A10, A10)), "")
Data retrieval in C10 is accomplished with,
=INDEX(A:J,MATCH(A10,A:A,0),MATCH(B10,$1:$1,0))
Fill down as necessary.
¹ Array formulas need to be finalized with Ctrl+Shift+Enter↵. Once entered into the first cell correctly, they can be filled or copied down or right just like any other formula. Try and reduce full-column references to ranges more closely representing the extents of your actual data. Array formulas chew up calculation cycles logarithmically so it is good practise to narrow the referenced ranges to a minimum. See Guidelines and examples of array formulas for more information.
Posting a revised answer following sample data provided by user (left prior answer as it might be useful to other users)
Assuming your data is in the range C6:K11
We’ll need four fields to show the resulting series: Row, Col, 'DateandTime`
Row: in cell M7 enter this formula and copy till the last record:
=IF(EXACT(M6,M$6),1,
IF(EXACT($N7,CHAR(133)),"",
IF($N7=1,SUM(1,M6),M6)))
Col: in cell N7 enter this formula and copy till the last record:
=IF(EXACT(N6,N$6),1,
IF(EXACT(N6,CHAR(133)),CHAR(133),
IF(N6=COLUMNS($C$6:$K$6),
IF(M6=ROWS($B$7:$B$11),CHAR(133),1),
SUM(1,N6))))
Date: in cell O7 enter this formula and copy till the last record:
=IF(EXACT($N7,CHAR(133)),"",
INDEX($B$7:$B$11,$M7,0))
Time: in cell P7 enter this formula and copy till the last record:
=IF(EXACT($N7,CHAR(133)),"",
INDEX($C$6:$K$6,0,$N7))
Fields Row and Col can be hidden

Resources