Using arrays and table names for unique value list - excel

I am building a summary tab in an excel workbook that is linked to numerous other workbooks to track hierarchical business data (ie. Numerous files for subordinate teams exchanging data with a master workbook that tracks them all). To make it easier and to increase uniformity, I'm using tables for all of the data and "building" table names based on each spreadsheet's specific criteria -- then using INDIRECT to bring the table references to life and complete my calculations.
To simplify the formulas I'm using, I've been using arrays to check all tables at once for pieces of data. For example, I've built a table for subordinate units (Ref_Units) which contains the units' names: ABC, EFG, XYZ. I then have a table (Ref_Tables) translate my Ref_Units into standardized table names. Formula is something like {=Ref_Units&"_2016_Sales_Rpt"}. Now I can make some SUMIFS using Ref_Tables that look in several different locations for data -- and to make updates, I only have to change Ref_Units.
My Summary tab will be the culmination of data coming from a dozen+ tables and upwards to 10 workbooks. The basis of the summaries are gathered from drop down lists specifying categories and years being summarized; these values are plugged into some INDIRECT formulas to generate table names and voila.
Now, the problem: let's say each unit records sales numbers and projections for specific items like "televisions", "stereos", "flatware", "candles", etc. and each of these items has also has a category accompanying it: "Electronics","Homewares", "Decor", etc.
I want a summary spanning all of the units' data pulling the numbers in each category (I should note that categories may change each month, so the list must be dynamic). To make the list dynamic (and to give myself the ability to summarize based on other criteria), I am using a formula I found online to generate a list of unique/distinct values.
Right now, I'm using INDEX/MATCH and COUNTIF to generate a unique list of categories. So, my unique list starts in cell C9 and the formula looks something like this:
{=iferror(INDEX(INDIRECT(Ref_Tables&"[Category]"), MATCH(0, COUNTIF($C$8:C8, Ref_Tables&"[Category]"), 0)),"")}
This function will not work. The only way I can get the desired results is to input multiple iterations of the formula, each using a single table name from Ref_Tables and joined with &.
Example:
{=iferror(INDEX(INDIRECT("ABC_2016_Sales_Report"&"[Category]"), MATCH(0, COUNTIF($C$8:C8, "ABC_2016_Sales_Report"&"[Category]"), 0)),"")&iferror(INDEX(INDIRECT("EFG_2016_Sales_Report"&"[Category]"), MATCH(0, COUNTIF($C$8:C8, "EFG_2016_Sales_Report"&"[Category]"), 0)),"")&iferror(INDEX(INDIRECT("XYZ_2016_Sales_Report"&"[Category]"), MATCH(0, COUNTIF($C$8:C8, "XYZ_2016_Sales_Report"&"[Category]"), 0)),"")}
**Remark: the look up arrays are strangely input here because they are actually cell references pulling in table name and column name being looked up, then brought to life with INDIRECT
Partially my problem is that the resulting formula is about 10 lines long which looks horrible, but it also looks too confusing to anyone using the workbook.
Is there any way to get the INDEX/MATCH to look at multiple tables for generate the list that is more concise?
I should note that my boss refuses to use VBA/macros/pivot tables because there are not many in my office skilled enough to troubleshoot issues in these areas. Help?

Related

Excel Macro to perform a formula where one column has the same value in several rows

I can't quite find the right code example to do what I'm looking to do.
We have an excel file with data from a project where a request can have several TASKs associated with it and different teams or organizations can be assigned. I'm trying to create a summary of whether the request was worked on by one team or another or "jointly" worked on (based on more than one team/org being assigned to tasks under the same request).
Here is the example and the result I'm looking for:
I want the code to be able to loop thru all rows checking where column A (request #) is the same value and builds an array of the value contained in column B (Team assigned) for each row where A has the same value. Then some sort of function to determine if the values in the array contain more than 1 team. If all of the TASKs were worked on by one team, just that team is the result, if more than one team worked on TASKs, the it results with "Joint".
This can be done without VBA, using formulas.
For the Result column in my screenshot, column E, I used
=IF(COUNTIFS([request],[#request],[team],[#team])=COUNTIFS([request],[#request]),[#team],"Joint")
The same formula without structure references reads like this:
=IF(COUNTIFS($B$3:$B$22,B3,$c$3:$c$22,c3)=COUNTIFS($B$3:$B$22,B3),E3,"Joint")
Apply the formula to the whole table column. If you don't want to use structured references, make sure to use absolute references for the column ranges, i.e. $B$3:$B$22 etc.
The Pivot table has Request and Result in the row areas, and the Tasks in the Values area. A pivot table needs to be refreshed when new data is added.
A dynamic result table can be achieved with the new dynamic array formulas available in Office 365 versions of Excel.
In H12 and I12 of my screenshot I use
=UNIQUE(Table1[request])
=XLOOKUP(H12#,Table1[request],Table1[Result])
The formula automatically spills down as far as required.
So, no VBA required, which means you can save as a regular .xlsx file, which will also run perfectly fine in the browser and on mobile devices.

How can I make a drop down list in Excel 2013 based on several conditions?

What I would like to achieve is that sellers can choose the STORE in the blue cell (either with a drop down list or by hard-typing the STORE name) and, based on the selection on the blue cell, the available POSITIONS for that particular PRODUCT and that particular STORE are show in the green cell as a drop down list.
Let's say I have an Excel workbook, which contains a worksheet with this table with products data, which is automatically imported daily from our Nav server with this layout. It has 4 columns including PRODUCT CODE, DESCRIPTION, STORE IN WHICH IT CAN BE LOCATED and POSITION INSIDE DE STORE (please, check screenshot). It contains 1.5k rows and it changes dynamically, for example, new items are added or positions are exchanged.
As you can see, the same product (PRODUCT 2) can be located in several stores (STORES 1, 2 and 3), and it can be in several locations on each store (POSITIONS 2, 3, 1 and 4).
Now I need sellers to report which of these items they pick and from where, not only the STORE but its POSITION inside the store too. They do it with another worksheet inside the same Excel workbook. It looks more or less like this (please, check screenshot).
I know the drop down list is achieved via Data Validation but I can't figure out the formula for this. I have tried several approaches like:
Array formula to return all POSITIONS in the same ROW, following this (Formula 2.): https://www.ablebits.com/office-addins-blog/2017/02/22/vlookup-multiple-values-excel/. It is quite slow to calculate on the 1.5k items and, once done, I can't figure out how to make Data Validation to look for the 4 or 5 or 10 POSITIONS returned by the array formula, which also need to be filtered by STORE (please, check screenshot for the closest that I have been, array formula returning POSITIONS from column E).
Same formula as above directly on the Data Validation list box, which returns only the first POSITION found.
VBA custom fucntions which are not allowed in the Data Validation box.
I feel comfortable with both Power Query and VBA, and forumla as well, and can adapt most of the code I see but I don't know why I just can't figure out how to achieve this, maybe it is only I am blocked or something but every path I start to follow ends up in a dead end.
Does anyone have an idea on how to approach this? It doesn't really seem that complicated but it is becoming impossible for me.
Thank you very much for your time!!
This is what I have finally done, just in case someone else is facing this situation.
Instead of a plain-text table for the POSITIONS, I created a PowerQuery importing that CSV. Named that worksheet _LOCATIONS.
Added a custom column (Column E) combining the PRODUCT and the STORE so I had something like a Unique Identificator, resulting something like this but in PowerQuery.
Combined column:
Sorted column E and sub-sorted column D, so I make sure the list will always be ordered as I need, and saved the query.
Then, in worksheet REPORT, I entered this formula to create the drop down list in Data Validation in cell D2:
OFFSET(_LOCATIONS!$D$1,MATCH($A2&"-"&$C2,_LOCATIONS!$E:$E,0)-1,0,COUNTIF(_LOCATIONS!$E:$E,$A2&"-"&$C2))
And I am able to choose from the available POSITIONS for the selected PRODUCT in the selected STORE.
Brief explanation:
I set the reference for the OFFSET function in the very first POSITION (D1), and then I move it the amount of rows detected by the MATCH function (which searches for the "PRODUCT 2-STORE 2" string in the newly created combined column) minus 1 (PoweryQuery table has headers) and 0 columns. This leaves me on the first occurrence of my string (but on the POSITIONS column). Then I make the offset as high as the amount of rows detected by the COUNTIF function (which counts all occurrences of my PRODUCT-STORE pair), returning an array of all the positions (column D) matching the PRODUCT-STORE pair.
Ask for formula in Spanish if you need it.

Excel Pivot Tables for multiple tags

I'm using Excel 365. I have a program that exports Excel files, and one field is a bunch of tags, separated by commas.
Let's say it looks something like this:
The program allows multiple tags (there's maybe 20 that could be changed in the future) to be selected as ingredients for each kind of candy. It is not a consistent number, though they seem to always be alphabetical.
I'm looking to make some kind of table by ingredient and chef, according to time, like this:
I'm trying pivot tables, but they come back with long ingredient lists, when I really want just one item per line. I also tried making an additional column for each ingredient, which searches the main column and returns yes or no based on if it's in the ingredients column. It's still not working to have a single item listed each row with pivot tables- it gets into lots of levels and sublevels that way.
It's very likely there will be more ingredients and chefs in the future, so I'm trying to stick to some pivot tables where people can push "refresh all" to get the new ones. Ideas?
If you can build your ingredients list manually and add the names across the top then you can calculate the totals using a SUMIFS formula.
=SUMIFS($F$2:$F$5,$B$2:$B$5,"*"&$A10&"*",$C$2:$C$5,B$9)
if you put the formula above in cell B10 then autofill across and down then the values will be calculated automatically.
To break it down so you understand what's going on
=SUMIFS(**$F$2:$F$5**,$B$2:$B$5,"*"&$A10&"*",$C$2:$C$5,B$9)
is the range you want to sum under the total column. It's locked using $ so it doesn't change when you autofill.
=SUMIFS($F$2:$F$5,**$B$2:$B$5**,"*"&$A10&"*",$C$2:$C$5,B$9)
The range you want to check with the tags in each cell, also locked.
=SUMIFS($F$2:$F$5,$B$2:$B$5,`"*"&$A10&"*"`,$C$2:$C$5,B$9)
The cell containing the ingredient you want to count with a star at each end to act as wildcards so it can return true when the cell contains the ingredient. The column is locked.
=SUMIFS($F$2:$F$5,**$B$2:$B$5**,"*"&$A10&"*",**$C$2:$C$5,B$9**)
last bit is the range of the chef list (locked) and the criteria above locked by row.
I can't think of a way to automate the ingredient list but hopefully the formula will help.

Excel: How to lookup a value that has multiple search criterias?

I'm looking to implement a formula that would return the total quantity attributed to a certain ID. I was relying on a classic IfError and Vlookup combo to get the data, but I have many suppliers that use the same vendor code (supposedly unique ID) for different branches working on different commodities (which act as separate entities from a logistics perspective).
I have to manually split up the quantity attributed to certain suppliers by looking for the logistics agent responsible for them, and when the same log agent handles multiple commodities for the same supplier, I manually dig for the material codes.
I would like to know how to synthesize the manual process I undertake in a single formula.
I was using this formula to get the data in a pivot table =IFERROR(VLOOKUP(TRIM(A2),Pivot!$A$4:$B$105,2,0),0)
And I need to incorporate three search criteria to get the qty of a specific supplier's sub-entities (Vendor ID, name of Log Agent, Material ID).
[Part of pivot table where I'd get data pasted as value ][1]
[Example of how the data is stored and result I get with Vlookup function][2]
[1]: https://i.stack.imgur.com/A1v0f.png
[2]: https://i.stack.imgur.com/BmFi3.png
With the following solution, you will need to fill all the cells with vendor id and PURCH_GRP_NAME. If the range is built from a pivot table, there is an option to "repeat" the identical values on every row.
Once this is done, you can use a formula like this (the XXXXXX is the search criterion. I did not understand where this is supposed to come from):
=INDEX($D$1:$D$105,MATCH(XXXXXX,$A$1:$A$105&$B$1:$B$105&$C$1:$C$105,0))
Press Ctrl+Shift+Enter to turn it into a matrix formula.

Excel Dynamic Drop Down List

I have two tables that get dynamically created from a database query; the first table is the source of the drop-down list, and the second is the table that I will apply the drop-down list via data validation. First table:
and the second table:
What I need, ideally through just Excel formulas, is an intelligently designed drop-down that shows only the dimension values associated to the dimension in question.
So in cells B3:B10, the drop-downs would show a,b,c. In cells C3:C10, the drop-downs would show 1,2,3. In cells D3:D10, the drop-downs would show x,y,z. Etc, etc.
I need this to be dynamic in the sense that a week from now my DB query may return a fourth dimension that would need to follow the same approach.
Not sure if this is even possible without writing some VBA, but I figure I'd see if anybody has any creative ideas. Cheers!
You have to use Name Manager and =INDIRECT() formula to achieve that.
First download the sample file.
Sample File
See this tip (By me). It will help you to see screenshots step by step. Link is here
Now in-case of your data you have to use some formula to filter data automatically when new data come. So that new data can organize for dynamic combo boxes. I can also do that for you if you are not able to do that. Then share your sample workbook with me.
It is very possible, but not simple. There are a several ways to implement this, depending on your requirements, how dynamic it needs to be, and the expected structure of the data (as I mentioned in a comment).
I will give one possible solution, that is mostly dynamic, and is the simplest to explain. You can use a similar logic to make it all dynamic.
This solution will retrieve the data from table #1 according to the dimension name, assuming it is not sorted, and return the values in the order they are given in the table.
For some of the ranges I create names for simplicity, and some are mandatory. In order to follow the formulas logic you need the named ranges I use.
Create named ranges for table #1: (Either by using the Name Box or using the Name Manager Ctrl+F3):
For the data in the column Dimension: DimName =B3:B11
For the column Dimenstion Value: DimValue =C3:C11
Create dimension values lists in a new sheet:
Put the dimension name in B2 ="Customer". (The available dimension names can be created dynamically as well, but I'm skipping this part for simplisity).
B3 (array formula - Ctrl+Shift+Enter) =IFERROR(INDEX(DimVal,SMALL(IF(DimName=B$2,ROW(DimName)-ROW(INDEX(DimName,1))+1),ROWS(B$3:B3)),1),""). This formula returns the k-th value for the "Customer" dimension.
Copy B3 down to as many rows you think you'll need. Let's say B4:B10, so B3:B10 will have the array formula. The first cells will have the available values and the remaining cells will be empty because of the IFERROR function.
In B1 we will count the available values using the formula =SUMPRODUCT(--(B3:B10<>"").
Do the same for "Product" and "Geography" in columns C and D.
Create dynamic named ranges for the lists: (using the Name Manager Ctrl+F3)
For the lists' data DimLists =B3:D10.
For the lists' headers DimListHeaders =B2:D2.
For the lists' counts DimListCounts =B1:D1.
*These names are mandatory for the data validation to work in another sheet.
Set table #2 data validation list sources:
Select B3:B10 in table #2.
Go to Data > Data Validation, and select Allow: List.
Put the following formula in the source: =OFFSET(INDEX(DimLists,,MATCH(B$2,DimListHeaders,0)),,,INDEX(DimListCount,,MATCH(B$2,DimListHeaders,0))). This formula finds the correct list in DimLists according to the column header in table #2, and also sets the returned range height according to the list count.
Hope this helps.

Resources