When creating a datasource using custom SQL for Tableau Server, Tableau Cloud or Tableau Desktop there is an issue that arises when one of the fields used in the query no longer exists. Tableau errors when you use this datasource and won’t let you edit it anymore. It will return an error like Unable to proceed because of an error from the data source
with details like Invalid column name
.
If you cannot edit the query within desktop/server/cloud then don’t panic, we can recover the original query and then rebuild the datasource.
.tdsx
(packaged datasource) or .twbx
(packaged workbook).twb
file or .tds
then you can skip this stepThe ‘x’ at the end of .twbx
or .tdsx
tells you it is a packaged workbook / datasource and we want to edit the files within it and so must unpackage it.
Fortunately this is simple to do, just change the file extension from .tdsx
or .twbx
to .zip
, e.g.
my_datasource.tdsx
to
my_datasource.zip
Then unpackage this file using the “extract all” feature in windows, or your favourite unpackaging tool.
Workbooks (.twb
) and datasources (.tds
) are just XML containing all of their configuration. If you know what you’re doing and you are careful, you can edit the XML yourself to make changes. That is what we are going to do. All you need is a text editor, e.g. notepade or VS Code.
Open up the .twb
or .tds
file with a text editor.
I would recommend using the search feature in your text editor to look for 'Custom SQL Query'
or for common words using in SQL like select
, from
, where
etc. This should help you narrow down the part of the XML where your query is stored.
Whatever the issue was with the query you can now fix and save the file. Just make sure the syntax is perfect as you will not get any prompts about errors with it here.
If you started with a packaged file (i.e. .twbx
or .tdsx
) then you now need to package it back into a zip file. You can do this using the Compress to zip file
option in windows.
Change the .zip
extension back to what you started with (i.e. .twbx
or .tdsx
).
You’re now ready to open up the file in Tableau Desktop to test whether it works and then publish back to server/cloud if needed.
We changed the custom sql used here, but you can extend this trick to change any of the configuration inside a workbook or datasource. Below are some examples of where I use this same trick to achieve different goals:
In Tableau Desktop it is hard to precicely set the size of a mark to be the same across multiple sheets. However, if you open up the .twb
file and find the part that sets the size of the mark, you can set the pixel size manually yourself. It allows much greater consistency and precision than using the Tableau Desktop interface.
Another handy trick is creating hexcodes with transparency. In the Tableau Desktop interface you are limited to what colour hex codes you can use, notable not letting you add transparacy values. However editing the .twb
file, like done here, you can add these values.
Perhaps the most common use case of this trick is to mass edit the file paths used in a workbook. Let’s saw your datasource reference a file path specific to your user and you give the workbook to a colleague who has a different file path (perhaps a networked file path) to those files. You can use this trick to edit the file paths all at once using find and replace on the .twb
file.