Power BI App script example
- Last UpdatedJul 18, 2024
- 2 minute read
This example demonstrates a simple method to incorporate scripting with the Power BI App using UDO objects that appear in the the ViewApp's Navigation Tree that point to specific statements in a layout script of the pane in which the Power BI has been placed.
In the example shown below, a Power BI App script has run to restrict the displayed monthly sales variance data to the months of May and June.
|
Before Power BI Script Filtering |
After Power BI Script Filtering |
|
|
|
The remainder of this example shows the essential steps to incorporate a Power BI App layout script into a ViewApp. In the example shown below, the ViewApp builder has created a set of UDO objects and assigned custom friendly names to them. During runtime, the objects appear in the ViewApp's Navigation Tree by their friendly names. The layout script should contain statements that compare the current focus of the ViewApp to the friendly names shown in the Navigation Tree.
elseif(MyViewApp.Navigation.Current=="AdvancedFilterMarApr")
|
UDO Objects for a ViewApp |
Navigation Tree Containing Objects as Nodes |
|
|
|
During runtime, the user selects a node from the Navigation Tree to set the focus of the ViewApp. In this example, the user selects a node from the Navigation Tree named AdvancedFilterWithLockedMayJun. A statement in a layout script compares the current navigation node to AdvancedFilterWithLockedMayJun. On a match, the following script statement executes to filter monthly fiscal data to show only the months of May or June.
elseif (MyViewApp.Navigation.Current=="AdvancedFilterWithLockedMayJun")
then MyContent.PowerBIViewerControl1.SetAdvancedReportFilter("Time","FiscalMonth","Or","Contains","May","Contains", "Jun","MAF3",false, true);



