Saw this was previously asked here on SO and had no solution and I can't find a solution through Google either.
I have a workbook with a tab called "Data" containing a table which is updated via a power query and another tab called "Calcs" with formulas referencing the cells in the table from "Data". When I refresh the table, it pulls data via the power query, but when it's done, the formula references change.
For example, before the refresh, I'll have formulas like this in the "Calcs" tab:
=COUNTIFS('Data'!$A$2:$A$26886,$A1060,'Data'!$K$2:$K$26886,'BY CAT'!$B1060)
After the refresh, the references for column A only change to
=COUNTIFS('Data'!$A$10242:$A$26886,$A1060,'Data'!$K$2:$K$26886,'BY CAT'!$B1060)
And it results ina #VALUE! error message.
How can I prevent Excel from creating this reference shift?
You might be able to get around this by using full column references:
=COUNTIFS('Data'!$A:$A,$A1060,'Data'!$K:$K,'BY CAT'!$B1060)
Full column references aren't always a good idea, but it might just work in this case.
Edit:
Table column references would be ideal, TableName[ColumnName]. These should work given that you are reading from a power query generated table.
Related
I have a changing power query which size changes based on the amount of PDF's from a folder. I have functions set up on a separate sheet tab to pull data from a range of cells from the power query tab. The main problem I have is if I load only a few of these pdf's my references will get deleted since the table range is getting removed. I have been trying to find work arounds to this, any help would be appreciated.
I tried to do a Pivot table of this data I need but I am trying to match certain criteria like an invoice and specific words to get a value. This did not work for my situation.
Example of Power Query
this is the data I am pulling that will turn into REF! if I take a pdf out and the rows shrink.
I have defined a table Table1 in source file.xlsx. When source file.xlsx is open, in target file.xlsx, I could use ='source file.xlsx'!Table1[#Data] in a cell to get the table data.
However, I realise that if I close source file.xlsx, that formula becomes ='\\Mac\Home\Downloads\source file.xlsx'!Table1[#Data] and its value becomes #REF!.
This is not the case for an external reference (link) to a cell range in another workbook; an external reference to a cell/range could still get value when the source file is closed.
Could anyone tell me how to update the table data even though when the source file is closed?
This is expected behaviour
From the Microsoft Help
Links to data tables residing in external files display #REF!
Symptoms
Consider the following scenario:
You insert a table in an Excel file, named for example source.xlsx.
In another file, named for example destination.xlsx, you insert a link to the data table which resides in source.xlsx.
You close both source.xlsx and destination.xlsx.
You open destination.xlsx and you choose to update links when prompted.
Result: the cells that are linked to the external data table display #REF!.
Cause
This is expected behavior for Excel.
New references to external workbooks that aren’t open will successfully parse without verifying the reference, but will return #REF.
When loading an external structure reference to a closed workbook, the reference is not updated by default. If you choose to calculate the formula the result is #REF! instead of the corresponding value.
Microsoft Help
As an alternative, create a query to the table. This can be refreshed from a closed workbook
To answer your question:
What you are seeing is how excel works at a cell formula level. If you type in
=[file.xlsx]Sheet1!Table1[#All]
This might be a little more of what you want, but it will give you the whole table.
For one column you can do:
=file.xlsx!Table1[[#Headers],[Date]]
=file.xlsx!Table1[Date]
You can create a defined name for Table1 as mytable then you would enter the formula =file.xlsx!mytable
All the above becomes similar to ='\\Mac\Home\Downloads\source file.xlsx'!Table1[#Data]
For an alternate method (recommended):
The very best way I have found to do this is using power query. This is not formulas in cells but it is like a database query tool. There are several people on You-tube making videos about using power query for this exact thing. I will step you through the process starting in the file where you want the data to appear. Go to:
Data > (Get & trasform Data) Get Data> From File> From Workbook...
In the popup window navigate to your file "\Mac\Home\Downloads\source file.xlsx" and click Import.
In the next window choose "Table1" (or an item that you want).
Now choose load and this data loads into your sheet.
If you want to transform the data of "Table1" then...
Data > Queries & Connections> (this pops open a "Queries & Connections")
Right click on Table1 then edit.
There are many options to choose from such as: remove columns, filter...
To calculate new columns use > Add Column which uses M function.
For Vlookup use Merge Queries,
For a Count, Sum, Average, or ... of rows (utilizing one or multiple columns) use "Group by".
After you "Close & Load" the table gets updated. If new values get entered into file.xlsx Table1, refresh the power query table and the data shows up.
Its a bit of a weird one but I have a linked table within my database. The table is an excel table with identical field headings and data types and until recently has worked fine however now when I traverse the linked table in Access the data will change every other move, changing from the original row to show data in the row below. Iv had a script output the values of the top row and it displays normally however I cant append this linked table into anything and I assume its this glitch.
Im stumped and would love any ideas as to how this happened and how it can be fixed.
This is an unusual post as I've never quite heard of this type issue. To sanity check things I would suggest that you delete your excel table from the navigation pane in Access - and then relink it.
So then perhaps I didn't understand, and I am wondering what is meant in your first post by: "The table is an excel table with identical field headings and data types"
A link to excel is a qualified "table" so to speak. You should be able to double click on it within Access, it opens in data sheet view and you see all the data but you can't write to it. You can't write back into the excel.
You can query it....
You can append the query results of the excel into a true Access table.
The following
=INDEX(Some_Table[Some_Name],1)
gets the cell from the array of rows from a table called "Some_Table" at the column of this table called "Some_Name"
And it works great no matter where the table "Some_Table" or the column "Some_Name" is.
However, if you delete/remove/refresh the table, Excel deletes the reference to the table and column and changes it to the worksheet:range, like this
=INDEX(Some_Sheet:some_range,1)
So we "lose" the reference to the table and to the column!
Is there a way to make "=INDEX(Some_Table[Some_Name],1)" fixed somehow so Excel does not mess with it?
Edit: Even if I use Data Validation to prevent changes to the cells Excel still manages to modify them and to remove the references to the table/column when it feels like it!
I have an Excel 2010 workbook with two SQL queries each returning data to a separate worksheet as a named table. They return the same db fields, but one is constrained on the values of one of the fields. I have additional columns using formulas to transform these field data, and these are also identical between worksheets.
Upon refresh, Excel autofills the formulae per the conventions of a named table. One of the sheets/tables--call it Table 1-- autofills with native references (e.g., for a field/column named variable, the corresponding formula uses [#[variable]] as its reference. However, the other table--call it Table 2--autofills with references to Table 1, i.e., 'Table 1'[#[variable]].
I have searched and replaced these several times, and rewritten the formulae, but each time I refresh the data query these references pop up. I searched to replace Table 1 with Table 2, as it occurred to me this may be a namespace collision and Excel just takes the first-created table as canon. This, though, doesn't fix the issue, nor did changing the column names to create a non-colliding namespace.
The only other thing I can think is that I'd copied the formulas from Table 1 and even though I removed the table name perhaps Excel has held onto the reference. Is there a table cache or such that Excel references to keep pulling these? Should I create a new query and new table and manually create the formulae, or would that run into the same issue?
[Entering this as an answer so it's not shown as an outstanding question.]
Creating the relevant tables from scratch results in no such namespace collision nor any wonkiness thus far, as we'd expect. I realized that I'd left something out of my initial question: I had copied, in whole or part (likely whole), the tab containing Table 1 to create Table 2. Even editing the resulting new SQL query and the formulae on Table 2, it seems Excel--in its effort to help--recalls several components of the table and does not update this cached information.