How to extract values based on criteria in a single column in Excel - excel

I am trying to extract a unique value from a pivot table from a separate sheet in an Excel workbook based on criteria from a single column.
In the example below, I want to extract the number of trucks sold based on make and color. I use the following array formula and one condition works (Ford, Yellow) and the other one does not (Dodge, yellow). Am I using the correct formula? Why does it only work for "Ford", but not for "Dodge"? Is this even possible using pivot tables in separate sheets? Thank you in advance.
{=INDEX($A$2:$B$9,MATCH(A13,$A$2:$A$9,0)*MATCH(B13,$A$2:$A$9,0),2)}
A B
1 Total Sold
2 Ford 49
3 Blue 20
4 Red 13
5 Yellow 16
6 Dodge 37
7 Blue 30
8 Red 6
9 Yellow 1
Inputs Outputs
Ford Yellow 16
Dodge yellow #REF!
Ford Blue 20

You can use
=GETPIVOTDATA("Sold",A1,"Truck",A13,"Color",B13)
where Truck, Color and Sold are the column names of your pivot table data.
Or try something like
=INDEX($B$2:$B$9,MATCH(A13,$A$2:$A$9,0)+MATCH(B13,{"Blue","Red","Yellow"}))

Related

Excel: How to add a column from other sheet based on a key column?

I have 2 list. Both have a lot of column. I would like to insert a column from Sheet2 to Sheet1 based on a ceratin key column. Also sheet2 have much more rows than sheet1 so it ll be inserted only partly and still there ll be elements with no matches. For an example:
Sheet1:
Names ID Car Color
John 1 Audi Empty
Andy 4 Toyota Empty
Mike 3 BMW Empty
Tony 2 Suzuki Empty
Sheet2:
ID Cost Color
6 200 Blue
3 200 Red
4 300 Green
5 100 Red
1 50 Black
I would like to get the "color" from Sheet2 to Sheet1 by using the "ID". Using Excel 2010. I suspect I need INDEX+MATCH combination, but the examples I can find are not detailed and more simple so I coudn't figure out how to use them.
How about inserting this formula on Column D in the first row, then dropping the formula down:
=VLOOKUP(B1,Sheet2!$1:$1048576,3,FALSE)
Or to find the column that contains "Color", use Index Match Match, as follows:
=INDEX(Sheet2!$1:$1048576,MATCH(Sheet1!B2,Sheet2!A:A,0),MATCH("Color",Sheet2!$1:$1,0))
This will find the value in Column B in Sheet2 and give you the row number, then it will find the Column that contains "Color" and return the Column number, with those two numbers Index will return your color.

Count how many distinct values (or get list of distinct values) in a filtered column

Is there a way to count the number of distinct values in a filtered column in Excel?
Using the formula at https://exceljet.net/formula/count-unique-values-in-a-range-with-countif I can count the number of distinct values in a range, but when that range has been filtered with an auto-filter I still get the unfiltered count.
For example:
A B
1 Scarf Blue
2 Hat Red
3 Gloves Green
4 Coat Blue
5 Balloon Red
6 Shoes Blue
Counting unique values in B with =SUMPRODUCT((B1:B6<>"") / COUNTIF(B1:B6,B1:B6 & "")) should return 3 as the distinct values are Red, Green and Blue.
If I auto filter Column B to just select Red items, the resulting table will look like:
A B
2 Hat Red
5 Balloon Red
In this case the number of distinct values retuned should be 1. But the formula above still returns 3.
The formula should also cope with multiple selections in the auto-filter, so for example filtering for Blue and Green should result in the following table:
A B
1 Scarf Blue
3 Gloves Green
4 Coat Blue
6 Shoes Blue
From which the formula should return 2 (Blue, Green).
Finally, if I am filtering on column A rather than B, the formula should still work. So If I am only interested in Hat, Scarf and Coat, filtering column A for these values would result in:
A B
1 Scarf Blue
2 Hat Red
4 Coat Blue
From which the formula should return 2.
(I'm using Excel 2013 and need to do this in a formula rather than using VBA etc)
I also found this page on office.com which I thought might help, but alas I can't get it to work for me.
This reference shows how you can exclude hidden rows using AGGREGATE
Excluding hidden rows with AGGREGATE
You can then use a standard way of counting unique values like this
Counting unique values with FREQUENCY
So if you were counting values in column B, you would need a helper column (say C) containing
=IF(AGGREGATE(3,5,B2),B2,"")
Then plug in the form of count unique that ignores empty cells
=SUM(IF(FREQUENCY(IF(LEN(C2:C10)>0,MATCH(C2:C10,C2:C10,0),""), IF(LEN(C2:C10)>0,MATCH(C2:C10,C2:C10,0),""))>0,1))
Or your formula if you prefer
=SUMPRODUCT((C2:C10<>"") / COUNTIF(C2:C10,C2:C10 & ""))

Conditional formatting in Excel based on formatted output in other table

Say,I have 2 tables...Tables are related...
1 3 5 7
8 8 9 10
11 12 13 14
&
2 3 5 5
1 1 1 1
3 4 4 4
I have highlighted top 5 values in first table using conditional formatting rules.Now I want to highlight cells in the second table based on first table...Assume 11 12 13 14 7 10 are highlighted in first table....I want to highlight cells in second table occupied same position as of in highlighted cells in first table..i.e. 3 4 4 4 5 1 should be highlighted...How can I do that
Use Excel functions RANK and/or COUNTIF to calculate a sequential ranking list column for the first table. The expression is explained here.
For the second table, you can then use conditional formatting based on the computed rank.
Might just be an elaboration of #Axel's answer and I agree the details of the question do not make sense but the position of a selection of top (or bottom) ranked cells in one array (say A1:D3) can be used to determine whether or not to format a cell in the corresponding position of another array (say H5:K7):
Select from H5 to K7, then HOME > Styles - Conditional Formatting, New Rule..., Use a formula to determine which cells to format and Format values where this formula is true::
=RANK(A1,$A$1:$D$3,)<6
Format..., select formatting, OK, OK.
Change the 6 to suit how many cells are to be formatted which for <6 could be more than five if the value ranked fifth is duplicated.

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

Specific transpose in Excel 2010

I would like to transform this:
id brand color price
1 bmw white 100
2 fiat black 200
3 audi blue 300
into this
id value
1 bmw
1 white
1 100
2 fiat
2 black
2 200
3 audi
3 blue
3 300
Headers (id, title...) are not important, all I need are values.
I've been searching for a solution for some time now, but can't find any.
Thanks for you help!
You can do this with Excel formulas. Assuming that your data are in cells 'A2:D4' and that your results begin cell F2, the following OFFSET formulas will transform the data as you want:
The first formula would begin in cell F2. This is the formula that gets and repeats the id:
=OFFSET($A$1,INT((ROW(F2)-ROW($F$2))/3+1),0)
The second formula would begin in cell G2. This one traverses the columns of the data:
=OFFSET($B$1,F2,MOD(ROW(F2)-ROW($F$2),3))
Both would be copied down as far as would be needed to transpose all the data.

Resources