Report with a variable number of columns

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
  • 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
    )))
    )


Reply
  • 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
    )))
    )


Children
No Data