Power Query/Pivot Table as reference to Data Validation - excel

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.

Related

Excel Conditional Lookup with conditions available in different Rows & Cols

I am stuck in a weird situation where I need to perform a simple vlookup but the using different data points.
I have a mapper where I have a %Achievement of the employee # Enter & State wise with their Slabs.
On second hand, I have a data sheet where I have the actual %Achievement of the Center state wise and I need to update the Slab from the above table. I have updated few of the entries FYR, however I have similar thing for almost 12000 entries of different combinations.
If you are using excel 365, combination of FILTER & XLOOKUP should work.
Step 1: Filter the row from slab sheet for the Centre/State which you need
Step 2: Use xlookup with matchmode 1
Here is the rough code snippet in col F2 of actual sheet:
= XLOOKUP(E2, FILTER([slab sheet]!D2:N100, ([slab sheet]!B2:B100=B2)*([slab sheet]!C2:C100=C2), [slab sheet]!D1:N1, "#N/A", 1)

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).

Excel filter Multiple Value in One Cell

I am looking for help on filtering multiple values in one cell delimited by a comma.
For example I have a spreadsheet with the following data:
Column A (Risk) Column B (Risk Mitigation)
Risk A Requirement1, Requirement2
Risk B Requirement2, Requirement6, Requirement7
Risk C Requirement1, Requirement3, Requirement9
When I filter on the 'Requirement Mitigation' Column I would like to see check boxes for the following:
Requirement1
Requirement2
Requirement3
Requirement4
Requirement5
...
Requirement9
So for my example when I only check the Requirement 1 filter box, only 'Risk A' and 'Risk C' rows would be displayed
Currently when I filter it does by the unique cell value, which gives me
Requirement1, Requirement2
Requirement2, Requirement6, Requirement7
Requirement1, Requirement3, Requirement9
Please note that above is just an example and I have thousand of individual requirements, so it would not be as simple as having one column per requirement.
I open to any suggestions including creating vbscripts.
Any help would be greatly appreciated.
This will be tricky.
First you'll need to create a form that will contain a list box and populate that list box with the Requirements you have in their correct syntax.
Then you'll need to create a loop that will go through every cell in a column and save each of them to a string, you could make a one dimensional string array to save them all in that as well.
Then you'll need a loop that will go through each string and use the split function to seperate the strings with a delimeter, you'll need to set your delimiter to ", " to ensure it seperates the strings at the commas.
Then you'll need a loop that will run after you've made your selection from the listbox in your form. this loop will go through every string in your 2D array and check if it contains any of the requirements in your listbox. If it is not, run the code: Range("B" & x).EntireRow.Hidden = True where x is the row, you can use one of the variables in your loop for this.
If you need more specific information that this I may need to see what you've already done, it is possible as well to use this method to automatically populate the list box in your form.

Data validation based on LOOKUP

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.

How To Reference an Excel Table Cell by Row Number or Horizontal Header Using Table Notation?

I'd like to reference a single cell in a table, from outside the table, using square-bracket sheet-formula notation.
Something like:
[MyTable[MyField] 3]
or
[MyTable[MyField] 3:3]
-to reference the 3rd row of the MyField column, or:
[MyTable[MyField] MyRow]
-to reference the MyRow row (leftmost row-header) of the MyField column.
Needs to work from outside the table, ie can't use # or #ThisRow.
Not looking for methods involving MATCH, INDEX, OFFSET, etc. Not looking for VBA methods. Just straightforward table-notation. Not looking for manually creating named ranges.
Why? Because, Tables :)
Pre-2013 Excel.
(PS, didn't there used to be a way (pre-Tables) to reference cells by row and column headers? I think it was maybe called "auto-naming", or something like that.)
heh, well this works:
=Table1[Column2] 3:3
So that's progress :)
Just awesome would be a way to reference a row by the contents of left-most column.
Thx!
You can also use index() function as in:
index(MyTable[MyField], 3)
So you get row 3 from the column MyField in table MyTable.
Reference:
https://www.ozgrid.com/forum/forum/help-forums/excel-general/116365-reference-a-single-cell-in-a-table-using-structured-referencing
We can reuse the idea of the intersection operator (i.e. a space between two references) and improve it to have the relative row number of the targeted item in the table, referred to as row_nb here:
=tbl[col] OFFSET(tbl[[#Headers],[col]],row_nb,)
or just without intersection actually (cf. comment below):
=OFFSET(tbl[[#Headers],[col]],row_nb,)
E.g. =Table1[Column2] OFFSET(Table1[[#Headers],[Column2]],2,)
This way you do not depend on the position of the table in the worksheet. Well, it yields a more complicated formula where table name tbl and column name col appear twice. Here are some comments about it:
You can of course keep the OFFSET(...) part only. The downside is that the formula will never return any error if row_nb exceeds the actual number of line items in the table. It'll return e.g. just 0 if the cells below the table are empty.
Keeping a formula that throws an error when we refer to an off-table row, we can further improve it: make it "dynamic" by letting tbl, col and row_nb be parameters:
=INDIRECT(tbl&"["&col&"]") OFFSET(INDIRECT(tbl&"[[#Headers],["&col&"]]"),row_nb,)
Assuming that we've defined tbl, col and row_nb as named ranges. Or else just use cell addresses:
=INDIRECT(A1&"["&A2&"]") OFFSET(INDIRECT(A1&"[[#Headers],["&A2&"]]"),A3,)
I'm not a big fan of INDIRECT but in this case it really comes in handy to let the formula adapt to various tables, columns and line items.
To handle tables that don't start at the first row of a worksheet, we can use the ROW() function. We can determine the first row of the data in the table with:
=ROW(myTable)
Using this and the Indirect() Function we can identify the first cell in a named column with
= myTable[myField] INDIRECT(ROW(myTable) & ":" & ROW(myTable))
The 3rd cell in that column would be:
= myTable[myField] INDIRECT(ROW(myTable)+3 & ":" & ROW(myTable)+3)

Resources