Export Data with Headers

I want export data to a text file and I want to have header rows, like reports can do. I have a database with a City field. I want the text output to list the City and then the following rows will have the data for records with that city.
I don’t see how to get the City name at the top of the group when I export data. I can easily get the City after the group. Like this:

Is there a way to do what I want?

There’s no “click the box” way to do that. In other words, this is not a built in feature of Panorama.

The easiest way to do that would be with a loop. Of course this will be much slower than using export or arraybuild.

I think it might also be possible using export or arraybuild and a complicated formula using the assign( and ?( functions. I’m going to leave that as an exercise for the reader.

I can think of a few ways, but arrayreverse( might be easiest.

I didn’t think of that. It’s a good idea if you don’t mind that the order of the data records will be reversed.

Perhaps I’m overlooking something, but wouldn’t sorting your array the reverse of the way you want it to appear in the report, grouping that the same way and then using arrayreverse( give you the desired order with the ‘header rows’ preceding the raw data? Except for the problem of a ‘grand total row’, if any, preceding everything else. And that line could easily be moved from first to last with text funnels.

You can always sort your data prior to any grouping using SortUp or SortDown so that the ArrayReverse ends with it in the desired order.

I used a loop as Jim suggested and which I have done before, and that works.

I then used the method suggested by John B, and that also worked. I want to group the data by County name and then alphabetically by Last Name within the County. These few lines work to do that.

Field County groupdown
Field «Last Name» sortdownwithin
letfileglobal fgresult = arrayselectedbuild(cr(),"",{?(info("summary")=1,County,"    "+«Last Name»)})

Thanks, John, for that suggestion. (Why didn’t I figure that out?)