Canvas apps
In a canvas app (or a custom page in a model-driven app), the Driver Tree shows your table and raises OnScenarioSave when someone saves a what-if scenario; your formula does the saving.
The examples use the samples table Sample Drivers, whose ID column is Sample Driver and whose Parent is a lookup to the same table. Replace the names with yours. The samples solution includes the canvas app Ninth Forge Driver Tree canvas sample, set up exactly as on this page.
1. Allow code components
Once per environment, an admin turns on Allow publishing of canvas apps with code components. See Install.
2. Add the Driver Tree
- Open your app in Power Apps Studio. Under Data, select Add data, then Sample Drivers.
- Go to Insert, Get more components, then the Code tab. Tick Ninth Forge Driver Tree and select Import.
- Go to Insert, Code components, then Ninth Forge Driver Tree. Set its Width to
Parent.Widthand its Height toParent.Height.
3. Bind it with text IDs
Canvas apps can’t map a lookup column to a code component, so leave Parent empty. Instead, give the tree each row’s ID and its parent’s ID as text, and list every column the tree uses:
ShowColumns(
AddColumns('Sample Drivers',
RowId, Text(ThisRecord.'Sample Driver'),
ParentKey, Text(ThisRecord.'Parent'.'Sample Driver')),
RowId, ParentKey, Name, Operator, Formula, Key, Actual, Target,
Unit, Format, 'Lower is better', 'Sort order', nf_ownername, Period, 'Scenario value')ShowColumns matters: with a shaped Items, Power Apps only fetches the columns the formula names, so a column you map but don’t list arrives empty. The owner column is named by its logical name, nf_ownername, because its display name, Owner, is also the name of the table’s built-in owner. Put the formula in Items, then set these on the Advanced tab, each column’s logical name in quotes:
| Property | Value |
|---|---|
nodeRecordKey (Record ID) |
"RowId" |
nodeParentKey (Parent ID) |
"ParentKey" |
nodeName (Name) |
"nf_name" |
nodeOperator, nodeExpression, nodeKey |
"nf_operator", "nf_expression", "nf_key" |
nodeActual, nodeTarget, nodeUnit, nodeFormat |
"nf_actual", "nf_target", "nf_unit", "nf_format" |
nodeInvert, nodeOwner |
"nf_invert", "nf_ownername". Lower is better colours a rising cost red. |
nodeSort |
"nf_sort". Needed for differences and ratios: the first child comes first. |
nodePeriod |
"nf_period", for the month picker and sparklines |
nodeScenario |
"nf_scenario", so saved scenarios come back |
AddColumns isn’t delegated, so the tree gets up to 500 rows by default (2,000 at most, under Settings, Data row limit). For more, Filter the table first, for example to recent periods.
4. Save a scenario: OnScenarioSave
Save scenario sets Self.scenarioJson to a list of { id, name, value }, with real record IDs, then raises OnScenarioSave. value is the what-if value, or blank to clear a saved one:
IfError(
ForAll(
Table(ParseJSON(Self.scenarioJson)) As s,
Patch('Sample Drivers',
LookUp('Sample Drivers', 'Sample Driver' = GUID(Text(s.Value.id))),
{ 'Scenario value': If(IsBlank(s.Value.value), Blank(), Value(s.Value.value)) })
),
Notify("Scenario not saved: " & FirstError.Message, NotificationType.Error)
)Name the scenario rows (As s): inside LookUp, ThisRecord is the table’s row, not the scenario’s.
OnScenarioChange runs on every what-if edit, undo or reset, if you want to show the edits elsewhere.
5. Licence key
What-if and Biggest levers need a Driver Tree key. In canvas apps, add the Environment Variable Values table under Data, then set Licence key to:
LookUp(
'Environment Variable Values',
'Environment Variable Definition'.'Schema Name' = "nf_NinthForgeLicenceKeys"
).ValueDon’t paste the key itself into the app. Without a key the tree and table still work, with a small mark.
Custom pages
A custom page is a canvas page inside a model-driven app, so the steps are the same. Add the page to your app from the app designer (Add page, Custom page) and publish both the page and the app.
Last updated