Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Output only a header row?

carl_steinhilber
8 - Asteroid

Seems like it should be simple, but I'm baffled.

 

I have a need to output datasets using the Output Data tool even if those datasets are empty.

 

In other words, I have 10 datasets that I output to .csv's for further processing. This further processing demands that 10 .csv's always exist, even if a given dataset is empty. So if a dataset is empty, I only want to output the header row... no other data.

 

Problem is, if an empty dataset is passed into the Output Data tool, it appears that it will not actually write a file. And if I pass in a dataset with just an empty row, I get a file but it has the header row and an extra row of delimiters for the empty data.

 

Anyone have any ideas?

7 REPLIES 7
CharlieS
17 - Castor
17 - Castor

Try using a dummy input that has all the necessary fields and use a Sample tool set to "First 0 rows" before the output. It will output a file with all the fields, but 0 records.

OldDogNewTricks
10 - Fireball

@CharlieS - Great solution!  I learned something new too.  I originally went a longer way to solve the problem, yours was much better.

carl_steinhilber
8 - Asteroid

This doesn't work for me, for whatever reason.

Selecting "First 0 Rows" in the Sample Tool results in an null resultset (of course), and, again, my Output Tool refuses to output a .csv from a null resultset.

 

My solution was to use the Formula Tool to set all the fields to a string containing their column name, then unchecking the "First row has column names" in the Output Tool. That's the only way I could get an output file.

OldDogNewTricks
10 - Fireball

@carl_steinhilber - I was able to get both methods to work.  Did you check out the sample workflow that I attached?  It sounds like my first method did it for you?  If so, please mark it as an answer.

carl_steinhilber
8 - Asteroid

@OldDogNewTricks Actually, I hadn't downloaded your workflow. I was only commenting on Charlie's solution. Opening up your workflow I see that our solutions were very similar, though you did a much better job (used the Cross Tab tool to handle dynamic column names, whereas I hard-coded them) so yes, I'll mark your answer as the solution.

 

I also had a "DUH" moment. The reason my Output tool wasn't writing a file was because it's dynamic, taking the target filename from a field in the dataset. And, of course, with 0 rows there was no value for the filename field passed in. Thus, our method is the only solution that would work in this situation. Charlie's will only work if the filename is known and hardwired in the tool.

trevorwightman
8 - Asteroid

I had a similar but related problem and thought I would share my solution if anyone needed it. I have a file with 600 columns and I want a list of all of the column names.

 

My solution was to take the first row and transpose the data. This put all of the headers in column 1 and then I used a select tool to remove the data in the second column. Cheers!

trevorwightman_0-1598540631215.png

 

j4jackycheng
7 - Meteor

I have the same question as @carl_steinhilber but i'm confused by the example from @OldDogNewTricks.

 

Not sure if that's due to Alteryx version different? i'm using 2020.3 x64 client.

 

With example from @OldDogNewTricks, there is no differences in behaviour with or without the Sample tool for me.

 

I found out for me, by default Alteryx would give the header in output even no rows returned, unless if you ticked the "Skip Filed Names" in the output tool.

The problem for me, i reckon is that because i used a formula tool to compute the output file name and file path, and the formula tool would ONLY works when there are at least one row of data in the incoming stream,  in a scenario my SQL returns 0 rows, the file name would not and cannot be computed by the "formula too'", hence the output tool is writing it to nowhere! (instead of writing a header row to a sheet).   The solution for me is to change my SQL query to union a dummy row, e.g. Field1 normally is = '123' , i'll dumy up with field1='No data found' , field2 = null, field3 = null... etc.  It's not elegant but it works, the main problem is the lack of global variable in Alteryx and our usual way of using formula to compute file name.

Labels