Excel Power Query and Cell refernces - excel

I am looking to have some summary stats for a table that is generated by a query on another tab, but all the approaches I have taken fail for some reason.
Using cell references - COUNTIF(INDEX(Errors!$A$2:$Y$692469,0,MATCH("INCORRECT",Errors!$A$1:$Y$1,0)),TRUE)
With this approach, when the table is generated, the references, even though they are anchored, adjust to the first column that is not part of the generated table.
Using structured references =COUNTIF(Errors[INCORRECT],"True")
This only works if the table already exists with that column. If it doesnt exist, excel wont even let me put in the formula. The formula error dialog pops and I cant save it there.
Creating a table stub that has the columns I want. For instance, I have a table with headers of ID, INCORRECT with one empty row. When I do it this way, the query ends up creating new columns (INCORRECT2) rendering the structured reference worthless.
So, any suggestions? One complexity is that the the table output does not have completely predictable column names. The ones that I want summary stats on are predictable, however, the other ones are not and in fact there could be a single other column or multiple. So that's annoying. I do know what the names (and quantity) of the other columns are. These are established connections.

So the indirect function was the way to go.
=COUNTIF(INDEX(INDIRECT("Errors!$A$2:$Y$692469"),0,MATCH("INCORRECT",INDIRECT("Errors!$A$1:$Y$1"),0)),TRUE)

Related

#VALUE using the FILTER function in Excel

I hear so many good things about the FILTER function in Excel, but I can't seem to get on with it. More often than not I end up with a #VALUE error. I'll usually get to the bottom of it, but this one has stumped me.
This is the formula:
=FILTER(Sheet1[#All],IFERROR((Sheet1[[#All],[Account]]=$D$1)*(Table2[[#All],[Duplicate 21711000]]=0),0))
I've put the IFERROR in because I thought perhaps a bunch of #N/A in the results could be causing an issue.
I've evaluated the Formula, and on the array on the Include side, everything seems to be working perfectly. The Boolean logic has worked, the 1s and 0s are in the right place to theoretically filter my list down to the few records I want to see. But when I click evaluate the final time, and it applies those 1s and 0s to the rows in the array, it results in the #VALUE error, and that's obviously all I can see in the cell.
Any ideas where I'm going wrong?
By the way, the point of this is to help a client who regularly pulls off a report from her accounting system, and then manually filters, copies and pastes the lines for new transactions onto separate tabs on her spreadsheet, over about 30 accounts. My plan is to use Power Query to bring the report into a tab in her spreadsheet, then use the Filter function to bring across the appropriate rows from the Power Query Table into each tab. That's the first criteria here.
I've created another table next to the PowerQuery table which uses a Count If to work out if that line has already been imported. So the second part of the criteria filters the list if the CountIf has registered a duplicate.
I can't just use PowerQuery everywhere, because she needs to then be able to add more columns and manipulate the data once it's been imported. So the final part of the job is to create a macro to copy > paste values, obviously copying the filter function into the row below first, ready for next month.
So Power Query imports all the data, Filter function extracts the specific data into each tab, and Macro locks in that data ready to be edited if need be.
If anyone can think of a better way of achieving the same result, I'm all ears.
So thank you #JvdV, the simple answer was indeed that the two tables were of different sizes, and FILTER requires for them to be the same size.
This caused a follow up issue though that in order to count if I had any duplicates in the sheet, I couldn't go with plan A and use a separate table, because it wouldn't dynamically change it's height when the Power Query table was refreshed.
I looked into maybe incorporating the table into the Power Query in the first place with a custom column. But this would mean that the PowerQuery would end up with 39 additional columns, which would all be brought across by each FILTER function.
So instead I did this. I know this is very niche, so probably won't help anyone, but I'm very proud of myself and want to post it somewhere:
=FILTER(Sheet1[#All],IFERROR((Sheet1[[#All],[Account]]=$D$1)*IF((COUNTIF('21711000 (125006) Int rec'!$C:$C,Sheet1[[#All],[Document Number]]))=0,1,0),0))
(I probably don't need the IFERROR anymore, but it works, so I'm not going to touch it, and it might be safe just in case there ever are any errors).
So this uses the fact that Excel spills now rather than needing specific array functions. Before I made COUNTIF into a separate column, but now I'm putting it in here, and it naturally spills in the background, essentially creating that column within the formula. Then the IF changes any 0 to a TRUE (1), and any other number (my duplicates) to a FALSE (0), and everything works.
It actually creates a circular reference, because the Filter is in column C, but I think that's okay for my purposes, because I don't want it to include the results from the filter anyway. I suspected that might happen, but it seems to be working so far.
I hope that can help someone.

Indirect reference to thisRow in Excel table

The situation: I have an automatic procedure for gathering data from different input-sheets and presenting in a pivot-friendly format. It appears others are in need of the same data, though they want it formatted slightly differently (and they are not friends with excel). I therefor have a version of my table formatted as they want it (with empty columns where my extract does not contain any data).
The table (both) is one line for each department for each year for each cost/income (from now, cost) category. The raw data contains the cost for each year, though some of the users want it to be cost delta from initial year. I want:
One column for raw cost (X). One column for delta cost (Y). One output column (Z) that contains one of those two values, depending on dropdown selection. The first two columns are situated to the right of the "select with mouse and copy these"-columns, so that I dont need to teach the other users how to select non-adjecent columns :P (just letting u know the level of understanding i have to work with here)
Now the naive approach to this would be to have an if-statement in column Z like this:
=IF(selected_Calc="Use raw cost";[#[X]];[#[Y]])
Alternatively nest more ifs (one for "Use difference to 2019", and potentially add more nesting if more ways to show the value should appear in future)
This works. However, it isnt as elegant as I would like it, and if I indeed end up with more ways to calculate this for other people, it will be a lot of nested ifs.
I was therefore considering something like this:
=INDIRECT("[#["INDEX(mapTab_out;match(selected_Calc;mapTab_in;0))&]]")
But this gives a #ref, and tbh i didn't really expect it to work.
The idea is though: .
Have a range mapTab_in. This has the different selections for the dropdown box.
Have the adjecent range mapTab_out. This has the name of the column (X,Y...) that contains the desired calculation)
Have in column Z a formula for selecting which column's (X,Y...) value is to be displayed in Z
The google-stuff I have found so far all seem interested in using the indirect function from outside the table, and usually want to sum an entire column. I have used this in the past. The "ThisRow" things like using # dont seem to work with indirect though. Any ideas, or have I simply made some beginner-error in my formula?
Assuming it's in the same table, you can take advantage of implicit intersection and simply use:
=INDEX(Tablename,,MATCH(selected_Calc,Tablename[#Headers],0))
where selected_Calc is the name of the column you want back. (You could make that the result of a further INDEX/MATCH if you want to use a lookup table for some reason.)

VLOOKUP and INDEX return #N/A when referencing another LOOKUP cell

I'm working on an Excel 2010 worksheet that uses a table that references a secondary table to generate a list of values.
More specifically, I have two tables: Table_Players and Table_ChallengeCalc. In Table_Players, I have the columns Players, Experience, and Level. I input the total number of points that a given player has under the experience table, and using this formula the level column tells me what level the player is:
Table_Players:
=LOOKUP(C6,
{-1;0;300;900;2700;6500;14000;23000;34000;48000;64000;85000;100000;120000;140000;165000;195000;225000;265000;305000;355000},{"0";"1";"2";"3";"4";"5";"6";"7";"8";"9";"10";"11";"12";"13";"14";"15";"16";"17";"18";"19";"20"})
Table_ChallengeCalc resides on a different sheet in the workbook, and references the Level value in Table_Players to pull a list of additional values from another table, Table_Difficulty.
Before I implemented the above lookup formula, I was just manually inputting the player's levels and in turn, the Table_ChallengeCalc was pulling the correct values for the remaining columns, using this to load the player's assigned level on Table_Players:
Table_ChallengeCalc:
=VLOOKUP([Players],Table_Players[Level],3,FALSE)
(Here's what it looks like when it works correctly):
However, as soon as I added the first LOOKUP value, the second VLOOKUP immediately became #N/A and in turn, so did all of the rest of the reference columns. If I remove the first lookup and manually enter the level again, the VLOOKUP immediately starts working again. I tried using a nested INDEX/MATCH statement, but it had the same results. As long as I'm using that first LOOKUP, Table_ChallengeCalc can't seem to pull the level value.
If I didn't know any better, it would seem to me that the workbook is trying to run the VLOOKUP simultaneously, if not immediately prior, the LOOKUP formula. Any ideas on how I can counter this, or is this one of those things where I've kind of hit the limitations of what an Excel workbook can do without additional software like VBA?
If I understand your issue correctly, then using the following formula should work for you:
=VLOOKUP([Players], Table_Players, 3, FALSE)
You currently have this in your table_array: Table_Players[Level], but your "[Level]" column is coming from the col_index_num: 3 in the formula, so you should not include this in your table array.

Print the results of a vlookup to a cell in excel

I have been working on a solution to this problem for a few hours now and I am basically no where except knowing that I don't know how to do it...So here goes.
I want to take the original data that I have in Excel that have 'code#s' for each 'category#'. With those 'code#s', I can look up the 'category#' name.
This has been so challenging because there are a varying number of categories for every 'title#'.
I have tried printing the 'category#' name next to 'title#', but it is seemingly impossible because Excel goes through every row in the original data and gives a True, False or #N/A instead of selecting and printing only the true statements without copying down a thousand rows. I want it to go through all the possibilities and only select the categories based on the criteria that they have the same 'title#' and their lookup code matches somewhere in the lookup table.
Thanks if you can offer any sort of help.
Here are some of the formulas I have tried:
IF(AND($M$5=TOP_TREND_CONTRIBUTORS!$W$2:$W$253,MATCH(TOP_TREND_CONTRIBUTORS!$A$2:$A$253,'Category Lookup'!$D$3:$D$30,0)<>"#N/A"),TOP_TREND_CONTRIBUTORS!$A$2:$A$253,FALSE)
....where M5, W:W is the 'title#', A:A is the code for the lookup-in that part I am trying to say that they are valid if the code registers in the lookup table and the 'title#s' are equal. The last part I am trying to get it to print the 'code#s' that are valid. But that only works when I drag the formula down all the rows.
Maybe I'm missing something, but I just tried to get from your original data and lookup table to the final result. I used VLOOKUP to put categories next to titles and then used pivot table to present the data in the way you wanted (after changing some settings of pivot table and fields). Is that what you need? (some words are in Polish, it doesn't matter).

How to inverse VLOOKUP for data entry?

My table has a date column to to the left (Column A). Other columns have share quantities and values. Using standard VLOOKUP, I can retrieve values for a given date.
However: I have new transactions, which regularly need to be added to the master table. What I need is an "inverse" function, that allows me to append (or even over-write) data to the underlying table.
So far, my searches for an "inverse" function only give me alternate ways to retrieve (with the columns out of order). Any suggestions for an appropriate method?
If I understand you correctly, what you are looking for is a script that can add data to the end of a table, or change data on an existing cell. Functions only work by reading data in other parts of the spreadsheet and outputting the result in the cell that they were written in. I don't think you're going to find a formula that sends data to another part of the spreadsheet.
If a script is what you're after let me know. I use scripts like that so I can code a few code snippets.
Please check INDEX MATCH functions.

Resources