Create filter for a drop down list that groups several rows together - excel

I have the following table:
A
B
C
1
Team
2
Team1
Working hours
10
3
Name
Ronald
4
Team2
Working hours
20
5
Name
Magda
6
Team1
Working hours
30
7
Name
John
Column (A2:A7) represents a dropdown list of {Team1, Team2}
Cell A1 selects the filter for that
I want now select in cell (A1) all data from Team1, to have a table looking like:
A
B
C
1
Team: Team1
2
Team1
Working hours
10
3
Name
Ronald
6
Team1
Working hours
30
7
Name
John
Does anyone know, if that is possible?
A solution would be, to fill every cell of column A with the Team value. However, this is not what I like
Another solution (I guess) is to connect these cells, but this makes it rather complicated if I want to add another attribute per team member (besides Working hours and Name)

I suggest you change your data orientation to be like this (check below picture):
I think it should do the job

How about the following?:
=IF(FILTER(A2:C8,(A1:A7=E1)+(A2:A8=E1))="","",FILTER(A2:C8,(A1:A7=E1)+(A2:A8=E1)))
This solution requires Office365.
The length of both ranges in the filter criteria need to be the same size (row numbers) as the range you want to filter. The range Just shifts (offsets) 1 row to have the second row showing.
Added an IF-argument to show blank cells as blank (they would appear as 0 otherwise).

Related

How to SELECT N values ABOVE and BELOW from specific value

If I have a table:
Column A
Column B
Column C
1
Jane
10
2
Stewe
9
3
John
8
4
Mike
7
5
Luke
6
6
Andrew
5
7
Carl
4
8
Sasha
3
9
Ariel
2
10
Carol
1
I would like to SELECT 3 rows above and below WHERE Column B = someValue .
IF query SELECT * WHERE Column B = "Andrew" result should look like:
Column A
Column B
Column C
3
John
8
4
Mike
7
5
Luke
6
6
Andrew
5
7
Carl
4
8
Sasha
3
9
Ariel
2
I know how to select one row, but cant understand how to select such range.
Thanks for ideas!
You can limit and offset inside your QUERY():
=QUERY(A1:C,"limit "&2+MIN(5,MATCH(D1,B:B,0))&" offset "&MAX(0,MATCH(D1,B:B,0)-5))
Well, this was fun...
If 3 above or below are not available then blank... rolling data around is a different proposition.
Below the image is the list of formulae used.
So, per cell not including the data validation that is based on cells B2:B11
A14 and dragged down:
=IFERROR(INDEX($A$2:$A$11,MATCH(B14,$B$2:$B$11,0)),"")
C14 and dragged down:
=IFERROR(INDEX($C$2:$C$11,MATCH(B14,$B$2:$B$11,0)),"")
Cells B14 through B20:
=IFERROR(IF(MATCH(B$17,$B$2:$B$11,0)=3,NA(),INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)-3)),"")
=IFERROR(IF(MATCH(B$17,$B$2:$B$11,0)=2,NA(),INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)-2)),"")
=IFERROR(IF(MATCH(B$17,$B$2:$B$11,0)=1,NA(),INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)-1)),"")
=E2
=IFERROR(INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)+1),"")
=IFERROR(INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)+2),"")
=IFERROR(INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)+3),"")
In Excel 365, you could try:
=INDEX(A:C,MAX(2,MATCH(D2,B:B,0)-3),0):INDEX(A:C,MIN(COUNTA(B:B),MATCH(D2,B:B,0)+3),0)
In Google sheets, on the other hand, the formula would be:
=INDEX(A:C,MAX(2,MATCH(D2,B:B,0)-3),0):INDEX(A:C,MIN(COUNTA(B:B),MATCH(D2,B:B,0)+3),0)
(spot the difference).
Excel
Google Sheets
This should produce what you want in all cases:
=IFERROR(FILTER(A2:C,B2:B<>"",ROW(A2:A)>=VLOOKUP("Andrew",{B2:B,ROW(B2:B)},2,FALSE)-3,ROW(A2:A)<=VLOOKUP("Andrew",{B2:B,ROW(B2:B)},2,FALSE)+3))
Of course, you can replace the two instances of "Andrew" with a cell reference (one where you type a changeable name).
This just looks up the row in a curly-bracket array formed from the names and row numbers and uses FILTER to keep results to rows between +/-3 rows of where the target name is found. If you choose the first name (or any other name), you won't get an error; because even if the target name were on Row 1 and the formula goes looking for anything "greater than or equal to 1 minus 3, all rows will be greater than a negative number. Same on the high end. You just won't get a full seven names if there aren't at least three other rows prior to or after the target row.
this not the best solution but it will work , you can use a helper column 'D' that contains the following formula =if(countif(INDIRECT("B"&ROW()+3&":"&"B"&ROW()-3),"Andrew")>0,TRUE,FASLE)
and u can query from here like this SELECT * WHERE Column D = TRUE

Excel conditional SUMPRODUCT / SUMIFS / Array Formula for optional dimension

I have a sheet of data with multiple dimensions like this:
A B C D E
1 COUNTRY FLAVOUR SIZE DATE SALES ($)
2 Japan Strawberry 100ml 10/12/14 100
3 Japan Banana 100ml 10/03/15 100
4 China Orange 200ml 14/04/15 30
5 France Strawberry 200ml 11/04/15 400
6 UK 200ml 23/04/15 250
7 ....
I want to aggregate this data over a date range, where the summary sheet has each dimension (country & flavour), and if I do not specify a dimension it sums all rows for that dimension.
A B C
1 COUNTRY FLAVOUR SALES TOTAL
2 Japan Strawberry 100
3 Japan 200
4 Strawberry 500
I can do this if all the dimensions are present (i.e. row 2 above) using a SUMPRODUCT or SUMIFS:
=SUMPRODUCT((data!A$2:A$100=A1)*(data!B$2:B$100=B1)*(data!D$2:D$100>[start_date]*(data!D$2:D$100<[end_date])*(data!E$2:E$100))
However I have not been able to figure out how to include all rows for a dimension if that input cell is empty (e.g. row 3 above). I tried:
Adding an IF statement or OR statement within the criteria (e.g. OR(data!A$2:A$100=A1,isblank(A1))).
Using a + in a SUMPRODUCT as an OR statement, (per this answer https://stackoverflow.com/a/27536131/1450420)
One solution is to have different branches of the formula depending on which summary dimensions are present, but that would quickly get out of control if I extend this same behaviour to further dimensions like Size.
Any help appreciated!
(I'm running Excel Mac 2011).
EDIT
Per #BrakNicku's comment one of the formulas I tried was =SUMPRODUCT(((data!A$2:A$100=A2)+ISBLANK(A2))*((data!B$2:B$100=B2)+ISBLANK(B2))*(data!E$2:E$100))
The reason this doesn't work is that sometimes my data has blank attributes (edited above). For some reason this formula double-counts rows where the attribute present matches (e.g. data!A6) but the other attribute is missing (e.g. data!B6).
EDIT 2
I can see why this double-counting is happening, because the + is summing the match because data!A$2:A$100=A2 (they match because they are both blank) and the match because ISBLANK(A2) (it is indeed blank). The question would remain how to achieve this without double counting. If needed a workaround could be to fill all blank cells on my data with some placeholder value.
The reason for double-counting values is here:
((data!A$2:A$100=A2)+ISBLANK(A2))
If a cell in A column is blank, both parts of this sum are equal 1. To get rid of this problem you can change it to:
(((data!A$2:A$100=A2)+ISBLANK(A2))>0)
Try this (I only included the first two, I left the dates out):
=SUMPRODUCT((((Data!$A$2:$A$5=A2)+(A2=""))>0)*(((Data!$B$2:$B$5=B2)+(B2=""))>0)*(Data!$E$2:$E$5))

If found in Column A, display entire row

I am trying to do a lookup but VLOOKUP does not seem to be the answer...maybe an INDEX and MATCH formula but I can't wrap my head around it.
Anyway, I have two tabs, one with data, and the other one will pull parts of the data from the first tab. In tab one my columns look like this (Google Sheets):
TAB 1 A B C D E
ROW 1 - PRODUCT DATE GARY TOM MARY
ROW 2 - Apples 9/1/2014 45 22 37
ROW 3 - Pears 9/1/2014 15 12 17
ROW 4 - Oranges 9/1/2014 18 27 61
ROW 5 - Figs 9/1/2014 4 2 7
ROW 6 - Apples 8/1/2014 35 21 31
ROW 7 - Pears 8/1/2014 19 7 11
ROW 8 - Oranges 8/1/2014 48 41 31
ROW 9 - Figs 8/1/2014 16 7 17
In TAB 2, I have the same Columns of Product, Date, Gary, Tom, Mary, but I would like to group their info by product and date. For example, TAB 2 would pull all data that matched Apples and display the entire row. So Tab 2 WOULD give these results:
TAB 2 A B C D E
ROW 1 - PRODUCT DATE GARY TOM MARY
ROW 2 - Apples 9/1/2014 45 22 37
ROW 3 - Apples 8/1/2014 35 21 31
I would then repeat this for Tab 3 which would pull data for Pears, tab 4 for Oranges, and so on. Of course we will be adding data to this each month so the formula in tab 2 will need to reflect new additions.
Thoughts?
1) in TAB 2 go to cell A1. right click, and then click data validation.
set up the box as shown below.
2) in cells B1:E1 put DATE GARY TOM MARY respectively
3)in cell A2 write the following formula: =filter('TAB 1'!A:E,'TAB 1'!A:A=A1)
4)choose your fruit from the dropdown box.
5)it might be worht formatting A1 with a yellow fill or something...
This is not going to be possible using standard Excel formulas. To accomplish what you wish I would recommend using several Pivot Tables.
Step 1
Start by selecting the data and navigating to Insert -> Pivot Table in the menu (depending on the version of Excel you are using, the Create PivotTable dialog may differ slightly).
Step 2
Select the PRODUCT column for your filter, the DATE column for your row groups, and the sums of GARY, TOM, and MARY for your values. Set the filter value to Apples (or whichever product you wish to display on this worksheet).
Step 3
Make any desired cosmetic changes to the PivotTable, and then repeat for each worksheet.
Notes
The PivotTable will not update automatically. If you intend to continue to add rows to your first worksheet, I would recommend setting the Table/Range (in step 1) to something like Sheet1!$A$1:$E$1000. Then, when an edit is made you can click the Refresh button in the menu to refresh the data.
If you don't want to have to refresh all tables manually, you can build a macro that will do so automatically.
I suggest using PivotTables, as opposed to formulas. You can name the data range you use which can be large enough to accommodate future entries and create a PivotTable on each tab quite easily - select the data or named range and do Insert -> PivotTable. Then, within the PivotTable Field List, use the "Choose fields to add to report:" filters and select the specific product you want for a given tab. This would work best if there are only a few handfuls of items as managing 100's of different products or product types may become tedious.
By using a large enough range, you can add data to the set and/or range and use the "Refresh All" button under the 'Data' tab to update the workbook.
Chandoo.org provides some great resources for PivotTable use. Also, when I first started I was fond of fiveminutelessons.com. To be honest, a quick Google search should turn up some decent help topics

Transfer data from one worksheet to the next based on cell values

I had trouble titling this, and I think it is better explained with examples. I am not an extremely experienced excel user, but was asked to figure this out.
Worksheet 1 (delivered by software) is formatted like this:
12/17/2013
Hour Delivered
00.00-00.59
Employee 1 18
Employee 2 17
Total For Hour 35
01.00-01.59
Employee 1 18
Employee 2 17
Employee 3 12
Total For Hour 47
... etc until hours 24.00-24.59
The number of employees in the group per hour is different each day, so i don't think that I can just simply reference the cells.
The worksheets that I want to transfer the data from worksheet 1 to are based on date, so there is one for each day. (12/17 worksheet, 12/18 worksheet, etc...)
And this is the format of the date worksheets:
Employee 00.00-00.59 | 01.00-01.59 | etc. until hours 24.00-24.59
Employee 1 18 18
Employee 2 17 17
Employee 3 12
Employee 4
Employee 5
So basically I need the data from worksheet 1 transferred over to the individual date worksheets. I believe, the amount of employees being different for each hour/day makes this difficult. Does anyone here have any ideas of how this can be accomplished?
Also, if there are any questions, please let me know.
This should be possible without any VB in two steps. First step is to add further columns to Worksheet 1 that normalise the data. Second step is to create a pivot table using that normalised data.
By "normalise" I mean add columns in Worksheet 1 for Date, Hour, Employee and Delivered using formulae that copy values from your existing columns A and B. Let me know if you need more help with that.
Edit: adding details ...
Suppose Worksheet 1 has the values you indicated in column A and B, and that you want Hour in column D. Suppose row 1 just contains column headings. Leave row 2 totally empty. The formula in col D needs to say "If the value in col A looks like an hour, then copy it, otherwise repeat the hour from the line above." A simple way to determine if a row in Worksheet 1 is an Hour is to look for a decimal point in position 3. So put =IF(MID(A3,3,1)=".",A3,D2) in cell D3 and copy that formula down.
I'm sure you can construct a similar formula for the Date, Employee and Delivered columns.
Maybe add a condition to the formulae to say "If the value in col A starts with 'Total' then leave the cell empty".
If there aren't a lot of data and the setup is exactly how you've displayed them above, a simple formula can solve this.
Assuming that my raw export is in sheet Base, cell A1 and my intended output starts in sheet Output, cell A1, you can use this formula on cell B2:
=IF(INDEX(Base!$A:$A,MATCH(B$1,Base!$A:$A,0)+ROW(1:1),0)=$A2,OFFSET(INDEX(Base!$A:$A,MATCH(B$1,Base!$A:$A,0)+ROW(1:1),0),0,1),0)
The premise is simple. It locates the correct hour using INDEX + MATCH, then OFFSETs it by the correct number of ROWs. This is assuming, of course, that your employees are in the same location under every hour (ie Employee 1 is always one (1) row below the hour, Employee 2 is always two (2) rows below, etc). We also add a check if the employee name matches so that it will return 0 if the employee is not there.
Here are some screencaps:
Sample data:
Output:
Of course, this is just the basic premise. If you have multiple dates in a sheet, it's just a matter of manipulating this formula further. Off the top of my head, locating the correct date and adding the correct offset can also work.
Let us know if this helps or if a VBA or the Pivot option seems best.

GETPIVOTDATA formula to return the total of a item within a given month

In my pivot table. I have my data setout like this..
M1 M2 M3
Country Item
Australia Item 1 5 3 3
Item 2 3 6 7
Item 3 4 6 6
Australia Total 12 15 16
Belgium
Item 1 4 5 7
Item 2 5 8 3
Item 3 3 7 3
Belguim Total 12 20 13
What im trying to do is get the total of Item 1 in M1 (which is 9) using the GETPIVOTDATA function.
Ive already been able to get the Country Totals for M1 using "Australia Total" "M1".
I thought this was possible, but looking at Excel 2010 help it seems to say that you can only refer to a total that's visible somewhere in the table. So, I think you need another pivot table that has doesn't include countries. Or you could change the one above so that Countries are to the right of Items. Then point your GetPivotData formula at that.
The specific line from the Excel page linked above is the last one: "returns #REF! because there is no total value of beverage sales for Davolio."
EDIT: If you want to use variables in your GetPivotData formulas this Contextures page has some great tips, especially the one at the end about referring to the Data field.
Only numbers shown on the sheet can be returned by returned by the GETPIVOTDATA function. In this case the solution could be to drag the Item field to the column. If now a cell with the number 9 is shown, you are able to retrieve it.

Resources