1

I started to use Tableau Desktop as a tool to visualise my data. However, my data is stored in CSV files with a date format name (e.g. datasample_yyyymmdd.csv). I need to be able to load in my files as the date is changing every day. How do I do this in Tableau?

I searched on Google for answers, but nothing clear.

2
  • Do you need your files aggregated for each new day or do you only want the most recent? Commented Nov 12, 2018 at 17:22
  • @vizyourdata I want to use the most recent one.
    – ECode
    Commented Nov 12, 2018 at 17:35

2 Answers 2

3

This can be done with Tableau alone if your data is not extremely huge.

  1. Create a union in your csv connection, select the type as Wildcard and enter the pattern. enter image description here

  2. Create a data source/extract filter to keep only Top 1 path. (Extract recommended) enter image description here

  3. Final Result (Here 20181111 is the latest file) enter image description here

PS: For some date formats, TOP 1 of max may not return the correct result. In that case, create a calculated date field from filename and apply TOP1 filter based on that.

2
  • Cool! I hadn't seen this before. Which version are you running? Commented Nov 12, 2018 at 22:14
  • @vizyourdata, 2018.2, but I remember using this even in 10.0. Please note that for some date formats, you might need to convert it to a date before applying the TOP filter as max may not interpret it correctly. Commented Nov 12, 2018 at 23:26
2

This is something that can be done outside of Tableau in a batch command or python script. Both can be automated with Windows scheduler if on Windows. Ultimately, you want to pick up the most recent file and copy it to something like datasample_today.csv then connect Tableau to that file. Tableau will then always be connected to the latest file. Here is how you could do it in Python.

Python:

import glob
import os

list_of_files = glob.glob('/path/to/folder/*.csv') #* is wildcard
latest_file = max(list_of_files, key=os.path.getctime)
print(latest_file)

from shutil import copyfile

copyfile(latest_file, '<your dir>\datasample_today.csv')

I'm not at all proficient in batch commands so you'll have to test this out and there is a lot here on SO to help.

Batch:

FOR /F %%I IN ('DIR *.* /B /O:-D') DO COPY %%I <<NewDir>> & EXIT

Not the answer you're looking for? Browse other questions tagged or ask your own question.