Forum Discussion

FICO's avatar
FICO
Community Manager
7 years ago

How to display VDL-TABLE with entity values across scenarios, relative to the first selected scenario

I have these Mosel entities:

KPIs: set of string

SummaryKPI: array(KPIs) of real

And I have a VDL view with:

    <vdl-table vdl-if="=scenarios.length > 1">

        <vdl-table-column

                vdl-repeat="=s,i in scenarios"

                 scenario="=i"

                 entity="SummaryKPI"

                 heading="=s.props.name" />

      </vdl-table>

Which displays the table as:

KPIs Scenario1 Scenario 2

Revenue              10               20

Cost                        5                 6

Is it possible to modify the VDL view to instead display the differences, relative to the first scenario selected? I'd like the table to appear as:

KPIs Scenario1Scenario 2

Revenue             10   +10 (+100%)

Cost                      5        +1 (+20%)

2 Replies

  • FICO's avatar
    FICO
    Community Manager

    Here's my current solution.

    <vdl-row vdl-if="=scenarios.length == 2">

      <!-- Custom table for comparing two scenarios -->

      <div class="table-wrapper">

        <table class="insight-table table-main table-condensed">

          <thead>

            <tr>

              <th>KPI</th>

              <th vdl-text="=scenario.props.name" />

              <th vdl-text="=scenarios[1].props.name">

              <th>Delta (abs)</th>

              <th>Delta (rel)</th>

            </tr>

          </thead>

          <tbody>

            <tr vdl-repeat="=k in scenario.entities.KPIs">

              <td vdl-text="=k.label" class="index" />

              <td vdl-repeat="=s,i in scenarios"

                vdl-text="=insight.Formatter.formatNumber(s.entities.SummaryKPI(k.value).value, '#,##0')"

                class="numeric" />

              <td vdl-text="=insight.Formatter.formatNumber(scenarios[1].entities.SummaryKPI(k.value).value - scenario.entities.SummaryKPI(k.value).value, '#,##0')"

                class="numeric"/>

              <td vdl-text="=insight.Formatter.formatNumber((scenarios[1].entities.SummaryKPI(k.value).value - scenario.entities.SummaryKPI(k.value).value)/scenario.entities.SummaryKPI(k.value).value, '#,##0.00%')"

                class="numeric"/>

            </tr>

          </tbody>

        </table>

      </div>

    </vdl-row>

    which produces this table:

    KPIs Scenario1Scenario 2Delta (abs)Delta (rel)

    Revenue             10                        20                   10             100%

    Cost                      5                           6                     1               20%

  • FICO's avatar
    FICO
    Community Manager

    Hi Alex, if all you need is to display differences with the first column then a custom render function may be your best bet.

    <script>

    function differenceFn(data, type, rowData, pos) {

    if (type === 'display') {

    if (pos.col > 1) {

    var baseVal = rowData[1];

    var diff = data - baseVal;

    var diffToken = diff < 0 ? '-' : '+';

    var percent = (100.0 / baseVal) * diff;

    return diffToken + diff + ' (' + Math.round(percent) + '%)';

    }

    return data;

    }

    return data;

    }

    </script>

    <vdl-table vdl-repeat-contents="=s,i in scenarios">

    <vdl-table-column entity="NAGENTS" scenario="=i" editable="true" render="=differenceFn"></vdl-table-column>

    </vdl-table>

    This will display the differences similar to how you requested in your first request and doesn't require you to create your own table from scratch.

    difference-table

    You would probably want to round differently and also use the name of the scenario in the table column heading attribute.

    HTH, Joc