Back in week 3 of the Data School (boy does that feel like an age ago), DS12 were set the challenge of building a suite of table calculation macros. The idea was that a user would be able to select a type of calculation (eg. percent of total, rank, moving avg, etc.) and designate the relevant categorical and numerical fields from the dataset that would be calculated. A common issue that we faced related to finding a way to have the macro selection fields update dynamically based on the fields in the dataset. In other words, if we were to plug a different dataset in with different field names, we would want those field names to appear in the macro user interface, as in the picture below.
I stumbled across a solution to this problem by accident. The key lies in setting up the macro to populate interface questions using the ‘Fields from Macro Input’ setting (at the bottom of the list below). The configuration panel will prompt you to select the data type of the data fields to populate the list. In this example, I used the Drop Down interface tool, but you can also do this with the List Box tool. You will only be able to select this field when your workflow type is a macro – in other words it won’t work if you’re building an analytic app.