Data validation based on LOOKUP - excel

I've got two tables. Table A and Table B.
Table A has the following three columns: "Attribut ID", "Attribut Name" and "Value".
Example rows from table A(comma representing a new column):
"10000, Length, 3M"
"10000, Length, 5M"
"10000, Length, 7M"
"20000, Depth, 1,5M"
"20000, Depth, 3M"
"20000, Depth, 4,5M"
Table B has the following three columns: "Product Number", "Attribut ID" and "Value"
Example rows from table B(comma representing a new column):
"38-500351, 10000, 3M"
The sheet will be used by clients to input data, so I want to make everything as simple and as validated as possible, to minimize errors. Currently clients put in the "Value" in Table B (3M in the example) manually.
My goal is to change this to be based on a dropdown list, or at least be validated, based on Table A. So if 10000 is put in as the "Attribut ID" in table B, only "3M", "5M" and "7M" can be put in as values.
I've found this topic, which seems very similar, but I've been unable to figure out how to use it. Any help would be much appreciated. Avoiding VBA would be preferred if possible.
I've succesfully adapted Axcel's answer. Here's the modified code to adapt it to my sheet:
=INDEX('Attribut værdier'!$C:$C;MATCH(INDIRECT("RC[-2]";FALSE);'Attribut værdier'!$A:$A;0)):INDEX('Attribut værdier'!$C:$C;MATCH(INDIRECT("RC[-2]";FALSE);'Attribut værdier'!$A:$A;1))
I've changed "," to ";" and the sheet references. Other than that I've made no changes and everything works.

Assuming we have a situation like this:
Note that the Attribut ID in column A is sorted ascending.
Create a Name named "ValueList" using the Name Manager which refers to
=INDEX(Sheet1!$C:$C,MATCH(INDIRECT("RC[-1]",FALSE),Sheet1!$A:$A,0)):INDEX(Sheet1!$C:$C,MATCH(INDIRECT("RC[-1]",FALSE),Sheet1!$A:$A,1))
How to use Name manager, see https://support.office.com/en-us/article/Define-and-use-names-in-formulas-4d0f13ac-53b7-422e-afd2-abd7ff379c64?ui=en-US&rs=en-US&ad=US#bmmanage_names_by_using_the_name_manage
The "RC[-1]" within the INDIRECT must be changed accordingly the language version of your Excel. For German Excel it has to be "ZS(-1)".
This named range will dynamically get the range in column C from the first occurance of the "Attribut ID" till the last occurance of this "Attribut ID" in column A. The "Attribut ID" is taken from the cell left of the cell it is assigned to.
Then you can use this named range as source for the list within Data Validation (Source =ValueList) for the dropdowns in column G.

Related

Power Query/Pivot Table as reference to Data Validation

WHAT I HAVE:
I have a large dynamic table made by Power Query similar to the following format:
X Y
[P27] [M258] [S1] [ML06] [RF01]
[P27] [M233] [S2] [ML08] [RF01]
[P27] [M334] [S1] [ML10] [RF03]
[P32] [M352] [S1] [ML01] [RF01]
[P32] [M344] [S2] [ML01] [RF01]
WHAT I WANT:
In another sheet, I want to data validate certain cells with drop down lists (List1 & List2) based on column X and column Y, respectively.
That means, that if I first choose P27 in List1 then List2 will only show me the options related to P27 - namely ML06, ML08 & ML10.
SOFTWARE:
I am using Excel 2016 and would gladly involve vba code.
WHAT I TRIED
I tried transforming the Query into a design like the following.
[P27] [P32]
[ML06] [ML01]
[ML08] [ML01]
[ML10]
but with no success.
I tried referencing column Y in the Query Table. This works, but it will give me a list of ALL the entries in column Y.
I tried making a PivotTable based on the Query Table. It can categorize my data, but I cannot manage to get it into the correct structure. On the attached picture you can see the current structure of the PivotTable and how I would like to structure it. PivotTableStructure
Is there a way to reference all the data entries inside the P27 & P32 categories of my PivotTable and use it as a Data Validation list?
Assume your data starts in Sheet 1 column A (you say X and Y, but those columns are next to each other and your data isn't). Also, assume your List1 data validation is in Sheet1 cell I5 (you'll have to adjust the below formula if you put it on a different sheet).
Create a named range called dvList2 with this formula
=OFFSET(INDEX(Sheet1!$D$1:$D$5,MATCH(Sheet1!I5,Sheet1!$A$1:$A$5,FALSE)),0,0,COUNTIF(Sheet1!$A$1:$A$5,Sheet1!I5),1)
Then create Data Validation of List and =dvList2.
This assumes that column X is sorted. It won't work if it's not.
The formula finds the first instance of, say, P27 and extends that list by the count of P27s in the list.

How can I make a drop down list that stores an index value in a hidden field?

I have an Excel spreadsheet where on Sheet 1 the Department Id is represented as a number and where on Sheet 2 there is a list of those numbers with the Department Name next to them.
If possible I would like some help and advice as I want to allow the user to select the Department Name from a drop down list and have it populate a hidden field with the department number.
Something like in Sheet 3 with the Department Id being stored for example in the C column on that page:
Sheet 1
Sheet 2
Sheet 3
This could be one approach.
If I have understood you correctly, the user will select the department name in a drop-down list in Sheet 3 and and the index number associated with that department name will appear. The user will not be limited to what name (andy, bob) it is in the adjacent column...
Result will be (notice this is a Excel Table!) :
We have the 3 sheets:
Select the data areas and click on "Format as Table", Select the option "My data has headers". Do this for all the 3 sheets.
Name your tables: "Design" -> "Table Name". I will use "Table1" for "Sheet1", "Table2" for "Sheet2" etc. It will make life easier when you link and refer in formulas. Notice that for "Sheet3" I also add a dummy column C. I name it "Index Number".
Go to "Sheet2" and select the range that you want to use as your drop-down list (in my case i choose Department Names and selected "B2:B8". Click "Formulas" -> "Name Manager" -> "New..."
This window will pop-up. Name it an easy name (I named it: "Department_Names") and check that the "Refers to:" is in this format "=TableX[Column Name]". In our case =Table2[Department]. Notice that the name manager don't use "B2:B8", rather is reference to the table column area. The last step is very important!
Go to Sheet3. Click on cell where you want to apply the drop-down list (I use B2 in the example). Click "Data" -> "Data Validation".
Data Validation window will now pop-up. Go to "List" and in the field "Source:" you write your named range as =Department_Names (the one I named "Department_Names"). The drop-down list will use the values in the range that "Department_Names" are applied to. In our case it will make a drop-down list of all the department names from "Sheet2", range B2:B8.
Go to "Sheet3" and enter the formula below in the cell C2 as shown in the picture.
Notice I use " ; "as delimiter (European version of Excel, US user will probably use" , ").
=IF([#Department]="","",IFERROR(INDEX(Table2[ID],MATCH([#Department],Table2[Department],0)),))
The first part creates our Index number:
...IFERROR(INDEX(Table2[ID],MATCH([#Department],Table2[Department],0)),)
Return the Index number from "Table2", Column ID. INDEX(Table2[ID]
lookup value in the MATCH formula comes from "Table3", Department
(drop-down list)
The lookup value will look in "Table2", column Department.
Will take care of 0 that will be created when nothing is selected in the "Table3", Department column (see next picture for example)
=IF([#Department]="","", ...formula...)
Formula without the =IF([#Department]="","", ...formula...)
You can hide the "Index Number" column in "Sheet3" if you don't want to have it visible.
Right click on the Column C header and choose "Hide".
Only for demonstration purpose here. I create a dummy column "Only for show hidden column values". So when the user selects a Department name, it will change the index number associated to that department.
So why the use of tables and named range?
Let's say you need to add a new department. We add a department in the "Table2" and we give it ID: 7 and Department Name: Department H.
What happens in your "Sheet3" is that the drop-down list will automatically catch the new row. The range named to "Department_Names" will adjust to the table rows because it's linked to "Table2[Department]". This is also true if you decrease rows for Table2. Source
I have not tested it, but I'm quite sure that you can link a table to an external source. So when you import your data to the table (given the headers is static) the table will be updated with "Refresh All" button in Excel. Something to explore and look further into :)
It can be done with INDEX/MATCH.
As an example:
Sheet1 contains your lookup table.
For simplicity sake Sheet1 has numbers 1 - 6 in the range A1:A6 and A - F in the range B1:B6.
1 - 6 are the primary keys and A - F are the descriptions.
Sheet2 has Data Validation in column A: Allow List using =Sheet1!$B$1:$B$6 as the Source. This will give you the drop-down in column A.
In column B, which is hidden, you have the formula =IFERROR(INDEX(Sheet1!$A:$A,MATCH($A2,Sheet1!$B:$B,0)),"")
The MATCH formula will return the row number in Sheet1 that the description appears in.
The INDEX formula will return a reference to the cell in column A on that same row - giving the Primary Key value.
If no match is found then #N/A is returned which is dealt with by the IFERROR statement.
This method will work if your departments are less than equal to 32.
In UTF 8 characters from code 128 to 160 are hidden (among many others). You can use these characters as your id key, you have to just concatenate them with your department name.
This is a screenshot of excel
3rd column is the Unicode character, 4th is concatenation of this character and the department name and last column is extracted id from the new department name.
These are the formulas
At the end it can also work if your departments are more than 32 but you have to find another slot of non-printable characters
You have to use the new department names as data validation drop downs where department entry is required and can extract the id from the entered department

How can I drive column titles from cell values outside of the query?

I have created a recurring (monthly) query tool. Each month, the name of a column will change. I would like the user to be able to type the value in a cell on the first sheet, and drive that value to become the title of a column in the table.
Thought 1:
Modify the following code:
#"Renamed Columns1" = Table.RenameColumns(#"Multiplied Column7",{{"Month1;BDG", "AAA"}})
to replace "AAA" with a call to a specific cell on another sheet directly in the "Renamed" step. Is this possible?
Thought 2:
Manage the change as column data by doing the following:
1. Demote the current column titles using "Use headers as first row"
2. Write an IF statement if the value = "Column7" then "value of the cell on the other sheet" else [Column7].
3. Then promote the top row to be column headers after the change.
Or is there a way easier way? My searches have come up dry!
Create a table in Excel that has the column name you want to use. For example, if you want "AAA", then put this in a couple cells in your sheet:
ColumnName
AAA
Select those two cells and go to Insert > Table and make it a table. (Check the box for "My table has headers".)
Under Design, you can name this table whatever you'd like, say, "ColNameTable".
Then in your code, you can use
Excel.CurrentWorkbook(){[Name="ColNameTable"]}[Content]{0}[ColumnName]
instead of "AAA". I.E.
#"Renamed Columns1" = Table.RenameColumns(#"Multiplied Column7",{{"Month1;BDG", Excel.CurrentWorkbook(){[Name="ColNameTable"]}[Content]{0}[ColumnName]}})
This pulls in the value of the first row (index starts at zero) of the column named ColumnName in the table ColNameTable from your current workbook.
Note: You can also use named ranges instead of creating a new table. See here: How can I reference a cell's value in a Power Query

Excel: Data validation source

I have a list and I want to display certain data based on another cell value. Let's call it "cell A1".
In my logic, every value of "cell A1" means different list items.
The problem is when I added other values to the possible data that "cell A1" could contain, the formula becomes very long and couldn't fit in the source field!
For example, if "cell A1" possible values are Tigre, Dog, Cat, Lion, Horse, Sheep and Turkey, the condition is:
=IF(D4="Tigre";'Sheet1'!$B$2:$B$1000;IF(D4="Dog";'Sheet2'!$B$2:$B$1000;IF(D4="Cat";'Sheet3'!$B$2:$B$1000;IF(D4="Lion";'Sheet4'!$B$2:$B$1000; IF(D4=" Horse";'Sheet5'!$B$2:$B$1000;IF(D4="Sheep";'Sheet6'!$B$2:$B$1000;IF(D4=" Turkey";'Sheet7'!$B$2:$B$1000;IF(D4="Val8";'Sheet8'!$B$2:$B$1000;""))))))))))
Check this image, the source field is already full! (before the end of the condition)
have you an idea how work around this issue or how to optimise the conditional formula?
PS: I'm a french user, so I apologize of my bad english! And, I know that I need to use "SI" instead of "IF" :)
Thanks.
I think you may be after something called dependent data validation.
Look here for a step by step tutorial http://www.contextures.com/xlDataVal02.html
As I see from your example, Val1 Val2 etc. are keys to redirect to specific worksheets. You can write the "mapping" data betweens these "Vals" and sheet names somewhere (possibly in a hidden worksheet or any available/hidden columns) and use it in the validation formula using a combination of INDIRECT and VLOOKUP. Say in this example I use Columns G:H in worksheet "mapping":
' Worksheet mapping
G H
Val 1 Sheet number 1
Value 2 Sheet2
Val3 My worksheet number 3
Now your data validation formula can be like this:
=INDIRECT("'"&VLOOKUP($D$4,mapping!$G$1:$H$3,2,0) &"'!$B2:$B1000")
p.s. you can then make the column mapping!G1:G3 your data validation list for the cell $D$4 that holds the keys.
I also notice here that if the ranges are not always the same (unlike in your example where they all are B2:B1000), you can also make the mapping "complete" by including the ranges in the redirection column (column H in my example).

Assistance on a Particular Nested IF Excel Formula

Here's a quick summary of what I am trying to do:
I'm trying to set up an Excel workbook that will allow users to paste the results of a SQL query into a RawData worksheet and have multiple other worksheets then grab that data and display it in various formats (graphs, charts, etc.).
This particular formula that I'm trying to write is supposed to look at a certain column in RawData, compare the number listed there to a "key" in the Key worksheet, and then return the text equivalent to the ID displayed in RawData in a new worksheet called StylizedData
For example, if RawData lists 1, then StylizedData will list "Configuration" because 1 is associated with "Configuration" in the Key.
Here is the formula:
=IF(RawData!F60=Key!$C$2,Key!$D$2,
IF(RawData!F60=Key!$C$3,Key!$D$3,
IF(RawData!F60=Key!$C$4,Key!$D$4,
IF(RawData!F60=Key!$C$5,Key!$D$5,
IF(RawData!F60=Key!$C$6,Key!$D$6,
IF(RawData!F60=Key!$C$7,Key!$D$7,
IF(RawData!F60=Key!$C$8,Key!$D$8,
IF(RawData!F60=Key!$C$9,Key!$D$9,
IF(RawData!F60=Key!$C$10,Key!$D$10,
IF(RawData!F60=Key!$C$11,Key!$D$11,
IF(RawData!F60=Key!$C$12,Key!$D$12,
IF(RawData!F60=Key!$C$13,Key!$D$13,
IF(RawData!F60=Key!$C$14,Key!$D$14,
IF(RawData!F60=Key!$C$15,Key!$D$15,
IF(RawData!F60=Key!$C$16,Key!$D$16,
IF(RawData!F60=Key!$C$17,Key!$D$17,
IF(RawData!F60=Key!$C$18,Key!$D$18,
IF(RawData!F60=Key!$C$19,Key!$D$19,
IF(RawData!F60=Key!$C$20,Key!$D$20,
IF(RawData!F60="",""))))))))))))))))))))
That whole process is working correctly all the way up until I get to the point where a row in RawData is empty. When the row is empty, it is displaying "No Subcategory", which is the text equivalent of Key!$C$2 and is contained in Key!$D$2. I'm wanting it to display nothing, which I'm trying to accomplish with that last snippet (IF(RawData!F60="","")).
Can anyone help me out here?
Thanks in advance.
Try,
=iferror(vlookup(RawData!F60, Key!$C$2:$D$20, 2, false), text(,))
=if(iserror(vlookup(RawData!F60,KeyArray,2,0)),"",vlookup(RawData!F60,KeyArray,2,0)
If the lookup value isn't found the cell gets a "" value. Otherwise it will search for the value contained in F60 in your key array and return the value two cells to the right.
With Vlookup() your array/range must have the values you are searching for in the first column. Your column/array must also include the column of values you want to return. For instance you would probably use something like $C$2:$D$20 for your key array. It also helps if your key values in your key array are sorted.
Good luck!

Resources