Contact us

Send
inqury

Knowledge base

home banner

bi@unija.com

  • Knowledge

  • Categories

May 10, 2021

Power BI: R Script Using Multiple Queries

Author: Branka Trifunović

For Power BI version 2.76.5678.782 (December 2019).

When we insert Run R script step in our query we get the table stored in a variable called dataset. If we want to edit tables from other queries we first have to assign them to variables.

Settings

Let’s first edit the settings. Follow the steps bellow.

Open Options and settings > Options > Privacy.

Select Privacy Levels and set to Always ignore Privacy Level settings.

Open Options and settings > Data source settings.

Select source R and Edit permissions.

Set Privacy Level to Public.

Confirm with OK.

How to: using two queries in one R step

Let’s use two queries in one R script. Queries are named Table1 and Table2. Follow the steps bellow.

We select the first table Table1 and open up the r script editor with Run R script.

We leave the window empty and confirm with OK.

We now have the following formula in the entry bar.

It tells us the variable dataset holds Table1 transformed with all the steps leading up to Run R script.

We add the name of the second table: dataset2 = Table2.

Confirm with Enter.

Queries are now assigned to variables we can use in R script.

Example: using two queries in one R step

Let’s now bind both tables using R. We follow the steps bellow.

Table1 Table2

 

Open up R editor.

Paste the following function.

df = rbind(dataset, dataset2)

Confirm with OK.

Tables are bound into one bigger table.

 

Index