Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Not Answered
+1
person also asked this
people also asked this
Replies
9 replies
Subscribers
5 subscribers
Views
8795 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
Reports
Report with a variable number of columns
Kyle Jorgensen
over 7 years ago
What would be the best approach to create a report with a variable number of columns?
I am creating a report that aggregates project cost data by customer and division that can be filtered by certain project attributes. I can create a DB view with a variable number of columns, but I'm not sure if Appian data types support a variable number of fields.
I've attached a mockup of what the base data looks like and what the report I am looking to create looks like.
OriginalPostID-258734
Discussion posts and replies are publicly visible
Parents
0
Chris
over 7 years ago
We do this frequently in reporting, standard use case is to show users a checkbox list of which data they would like to view in the report. The a!gridField's columns parameter is defined as below, utilizing a!applyComponents() to dynamically create the requested columns:
a!applyComponents(
function: a!gridTextColumn(
alignment: "CENTER",
label: _,
field: _,
data: _
),
array: merge(
apply(fn!displayValue,local!columnSelection,local!columnOptionsValue,local!columnOptionsName,null),
local!columnSelection,
apply(rule!reportGetColumnData,local!columnSelection,local!gridData.data)
)
)
2 arrays are used on the report for columns, one for column name (local!columnOptionsName) and one for column field (local!columnOptionsValue). In the merge() above, displayValue is used to obtain the label since the physical selection of field values is stored in local!columnSelection.
For the data parameter, rule!reportGetColumnData is iterated through to return an array of data arrays, rule definition is:
=index(ri!data,ri!column,null)
For more flexibility you can replace the gridTextColumn function under applyComponents with a new expression rule that returns differently depending on field values. Here we may hard code in certain behavior based on the field - users can select any field they like, but if the field being displayed is one with a special case, format it accordingly:
a!gridTextColumn(
alignment: "CENTER",
label: ri!label,
field: ri!field,
data:
if(
or(
ri!field="value",
ri!field="freightInboundTotal",
ri!field="freightOutboundTotal",
ri!field="totalOrder",
ri!field="totalExtendedCost"
),apply(rule!displayPrice,ri!data),
if(ri!field="step",apply(rule!getStep,ri!data),
if(ri!field="priority",left(ri!data,1),
ri!data
)))
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
Reply
0
Chris
over 7 years ago
We do this frequently in reporting, standard use case is to show users a checkbox list of which data they would like to view in the report. The a!gridField's columns parameter is defined as below, utilizing a!applyComponents() to dynamically create the requested columns:
a!applyComponents(
function: a!gridTextColumn(
alignment: "CENTER",
label: _,
field: _,
data: _
),
array: merge(
apply(fn!displayValue,local!columnSelection,local!columnOptionsValue,local!columnOptionsName,null),
local!columnSelection,
apply(rule!reportGetColumnData,local!columnSelection,local!gridData.data)
)
)
2 arrays are used on the report for columns, one for column name (local!columnOptionsName) and one for column field (local!columnOptionsValue). In the merge() above, displayValue is used to obtain the label since the physical selection of field values is stored in local!columnSelection.
For the data parameter, rule!reportGetColumnData is iterated through to return an array of data arrays, rule definition is:
=index(ri!data,ri!column,null)
For more flexibility you can replace the gridTextColumn function under applyComponents with a new expression rule that returns differently depending on field values. Here we may hard code in certain behavior based on the field - users can select any field they like, but if the field being displayed is one with a special case, format it accordingly:
a!gridTextColumn(
alignment: "CENTER",
label: ri!label,
field: ri!field,
data:
if(
or(
ri!field="value",
ri!field="freightInboundTotal",
ri!field="freightOutboundTotal",
ri!field="totalOrder",
ri!field="totalExtendedCost"
),apply(rule!displayPrice,ri!data),
if(ri!field="step",apply(rule!getStep,ri!data),
if(ri!field="priority",left(ri!data,1),
ri!data
)))
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
Children
No Data