Output category based on multiple inputs - excel

I have 8 combinations o triplets, each with a name attached to them. For example:
Category a = 1,2,3
Category b = 3,1,2
etc...
Each value in the triplet is either 1, 2 or 3.
I need to be able to input 3 values (also 1,2 or 3) into 3 cells, and I need the corresponding category to be displayed next to them (based on the 8 hard coded variants).
For example: if I were to enter 3 1 2 into the three cells, "Category b" would show up in the 4th cell.
Here is a screenshot of what I need:
The yellow cells are hard coded.
I have a long list of green cells.
I need to calculate the category in the blue cells based on the green cells.

use this in E2:
=INDEX(G:G,AGGREGATE(15,6,ROW($G$2:$G$9)/(($H$2:$H$9=B2)*($I$2:$I$9=C2)*($J$2:$J$9=D2)),1))
Then copy down

Related

excel365 - Conditionally format rows based on two string values?

Excel noob here. Lets say I have a sheet.
.
A
B
C
D
1
Adam
3
No
No
2
Betty
13
Yes
No
3
Chris
12
No
Yes
4
Dave
0
Yes
Yes
5
Emma
1
No
I want to conditionally highlight cells in multiple ways:
if column C and column D both contain the word 'Yes' colour the row green (e.g. match row 4)
if column C and column D are not the same, colour the row yellow (e.g. match rows 2,3)
if column C or D are empty, colour the row red (e.g. match row 5)
I set up two worksheet conditional formatters
=AND(SEARCH("Yes",$C2)>0,SEARCH("Yes",$D2)>0) is set to be green
=$C2<>$D2 is set to be yellow
=OR(ISBLANK($C2),ISBLANK($D2)) is set to be red
However, I'm getting mixed results. I get green rows where C and D are No or where C and D are different. I don't get any formatting for the second or third rules.
I tried just matching column values directly; =$C2="Yes" doesn't match, hence resorting to SEARCH.
Your observed behaviour is because of the commonality between rules 2 & 3, i.e. if C2 differs from D2 then it is, superficially, because the content of those cells differ but, if one of the cells is blank, when the other isn't, then both rules 2 & 3 are satisfied simultaneously.
In the screenshot below, I have made the assumption that 'half-blank' rows are to be identified before 'non-equal' rows:
the formula for 'equal' rows is
=AND(COUNTIF($C1,"*Yes*"),COUNTIF($D1,"*Yes*"))
(COUNTIF() is used because it caters for Yes being found within a longer string of text and, if not found at all, will return 0, which is interpreted, inside the AND() function, as FALSE, whereas if Yes is found then the function will return 1, interpreted as TRUE)
Given the non-independence of your rules 2 & 3 it is important that the rules implemented are prioritised as illustrated in the screenshot, which can be achieved by using the up and down buttons (highlighted) to move the currently-selected rule either up or down.

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.

Excel Arrange multiple Columns

I have a data like this in excel:
1 1
1 2
2 2
3 2
And I want the result to be displayed like this:
1
1
1
2
2
2
2
3
Its like a ascending sorting. If the number in columnA <= columnB, it will be display first, at the same time, columnB will have a empty cell or blank value.
I have looked for this for a while but no one has the problem like this.
I would prefer a formula rather than VBA code.
Please advise, thanks!
Edit: I hope this explanation will be easier to understand
Data (A1:B2) - Result (C1:D4). Each number in Data (A1:B2) is a result of complicated formula so I cannot change its position
A B C D
1 1 2 1
2 3 4 2
3 3
4 4
Honestly, if you want to avoid VBA, here's a manual process that would give you the results you want:
Color each column (ie. Column A Red and Column B Blue)
Place values of column B under column A
Sort & Filter by Sort Smallest to Largest
Copy the contents of column A to column B
Last for Column A Find and Replace all* with format Blue then do the same for column B only with format Red. (See below for more info on how to do that).
Following those steps isn't the most conventional, but it will give you the results you wanted without VBA.
*Find and Replace based on font color:
1. Press Ctrl-H
2. Click Options
3. Click Format > Font > then select your font color > OK
4. With the Find What blank with the font color and the Replace With blank click Replace All.

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 & ""))

Excel line up data

I'm a total Excel nub and can't find the answer I'm looking for. Must be easy peasy, but since I'm not into Excel I also don't know what to look for. Sorry if I'm having my question wrong.
I have output in Excel like this:
A 1
A 2
A 3
A 4
B 1
B 2
B 3
B 4
B 5
B 6
and I want it like this:
A 1 2 3 4
B 1 2 3 4 5 6
this question is quite complex in a way.
let me explain it more in detail:
as you see above, we have two columns A and B, you have text strings in column A , these text strings could be repeated. As you see in the example, there are 4 As, 5 Bs, 3 Cs 1 D and 3 Es. In column B each one of these strings have different corresponding values. For example, text strings B in column A has five corresponding values in column B, namely 11, 12, 13, 14, 15, and 16.
Now we want a list of UNIQUE values from column A, and lets say, we put this list in column C and then for each of these unique values in column C we want to list their corresponding cells in column B and put them HORIZONTALLY in front of each of these unique text strings in column C.
For this you need two kinds of formulas:
Formula 1 to calculate the list of the unique values in column A :
this goes in C2:(leave C1 empty)
=IFERROR(INDEX($A$1:$A$999;MATCH(0;FREQUENCY(IF(EXACT($A$1:$A$999;TRANSPOSE($C$1:C1));MATCH(ROW($A$1:$A$999);ROW($A$1:$A$999)); ""); MATCH(ROW($A$1:$A$999);ROW($A$1:$A$999))); 0)); "")
this is an array formula, so press ctrl+shift+enter to calculate the formula, and drag and fill down as many as you want in column C.
*Formula 2 to find and list horizontally the values from column B *
=IFERROR(INDEX($B$1:$B$999;SMALL(IF($C2=$A$1:$A$999;ROW($A$1:$A$999)-ROW($A$1)+1);COLUMN(A$1)));"")
this is an array formula, so press ctrl+shift+enter to calculate the formula, put this in D2 and drag and fill down until the last cell of column C. then select D2 to D6 and drag and fill horizontally. You should get all of the corresponding cells in front of each unique item.
P.S. adjust the formulas to meet your regional settings by replacing ; with , I suppose.
Finally here is the link to an example sheet downloadable from here .
This is very generic but hopefully will help.
Highlight the cells that you want to transpose to.
Type the equation..."=TRANSPOSE(B1:B4)" (edit as necessary).
While the cells are still highlighted, press "ctrl+shift+enter". (brackets should appear around the equation)
Finish editing the cells.
Celebrate

Resources