Excel table reference gets replaced when table gets refreshed - excel

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!

Related

Add text in front of grouped values in pivot tables

I'm trying to create an Excel Pivottable that grabs data from an Access Query and then shows the values grouped by what I want. That part works fine enough, what I would like to know is if it is possible to add text infront of grouped values in a way that is smart? The purpose is to just be able to change which Access database it should grab data from and have a standardised view where no manual changes have to be made.
What I currently have:
What I would to have:
As far as I can see I can add it manually, but there might be new cases of Øxxx types.
I would add reference table with columns sufficient to join to your view and then "prefix text" column that would be appended in front of the existing (quantity in english?) column. Or you could add it to the pivot. This method let's you add/delete rows from the reference table as needed.
If you cannot alter the access side for some reason, then another way is select all the raw data to a sheet and then use VLOOKUP or some other formula to add the prefix. And then pivot this data sheet.

Updating a table from a power query changes formula reference

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.

Excel 2010 check cells in a row contain data before the Selection Change fires

I have an Excel 2010 data table which is driven by a query from MSSQL. The underlying query changes depending upon what options the user selects in the Excel workbook. I'm okay with changing the query and pulling the data.
After the data has been selected multiple users will be able to edit and append data to the Excel table and these changes will post back to the SQL database table. Due to the database table structure some of these cells within a given row are mandatory before any data can be inserted into MSSQL and/or potentially updated.
So what I'm trying to achieve is checks on whether certain columns in a row are blank after a cell is edited (I can do this via Worksheet Change) and also before they move off that row so I can bring up a message if all mandatory columns haven't been entered. I can't see any events that fire before Selection Change. My only thoughts on a workaround is to have a global variable row marker that is updated on Selection Change, i.e. it will store the previous row number. I can't use Excel's standard data validation functionality looking at blank cells because although this is fine for a currently correctly populated row that is being edited, inserting new rows or appending directly to the bottom of the table will constantly error as all those mandatory columns will, of course, be blank. Currently I am using conditional formatting to at least highlight columns/cells that require input although this doesn't force users to actually do it. Data cannot be stored within MSSQL until these columns contain data so if they don't fill them in and refresh the table for whatever reason, whatever they have entered will be lost. Obviously this is bad, m'kay. I am concerned about both the Worksheet Change and Selection Change events constantly firing and how that will affect workbook performance.
Any suggestions would be appreciated. Maybe I'm going about this all wrong so any ideas to make this more efficient would also be well received. The user base do not want to see UserForms or MS Access even though it would make this activity very easy. They are too used to the look and feel of Excel sheets.
your best way is to copy the table into 2d array or some other data structure in memory such as dictionary or collection. and than manage each change in memory. this one is very efficient but requires a lot of code. with excel the only problem you have is the key the rest is vlookup and true false questions. vlookup will find the original value and then you have current data + previous data + the logic... is the new data ok?

Pivot Table returns wrong value on one row

I have a very strange problem. I built a macro that refreshes several PivotTables. Everything is fine except for one PivotTable where one value "AGHF21A#BFF" in the source gets changed into "54r" in the Pivot Table. Other PivotTables also get data from this source and they all get the correct value. This only happens with this specific case from a list of 30 products, this is the only one that changes the value in the Pivot Table.
I tried everything Excel would allow me do. I changed the format to string/general. I tried to do a calculated field. The strange thing is that if in the source data I add let's say any character, remove any character or change any character then the pivot table does recognize the code and does not change it to the strange code "54r." I have never seen any Pivot table do this before.
The Macro downloads different reports into Excel and then it refreshes the PivotTables. Any help would be very appreciated.

Two Excel tables created from SQL queries collide in formula auto-fill

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.

Resources