Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
jainprashant21
New Member

Send filtered data from Power BI to R script

Hi all,

 

I need to send my selection using Power BI filter to R script. 

Currently, whatever fields we select, those fields are available as dataset inside R script environment.

But, my requirement is not to use the fields but to use the selection of particular row of those fields in R script.

Is there any way to make it possible in Power BI to send only my selection related data into R script instead of whole field?

 

Thanks in advance

Prashant

1 ACCEPTED SOLUTION

You can filter the data before passing it to r  

e.g. this filters from a testParam

 

let
    Source = List.Generate(()=>10, each _ > 0, each _ - 1),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Column1] = testParam),
    #"Run R Script" = R.Execute("# 'dataset' holds the input data for this script#(lf)#(lf)#(lf)newdata <- dataset",[dataset=#"Filtered Rows"]),
    #"""newdata""" = #"Run R Script"{[Name="newdata"]}[Value]
in
    #"""newdata"""

 

You can also change the code used for r based on params. 

e.g. this filters from a testParam by changing the r code.

 

let
    Source = List.Generate(()=>10, each _ > 0, each _ - 1),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Run R Script" = R.Execute("# 'dataset' holds the input data for this script
#(lf)
#(lf)SearchValue = '"&testParam&"'
#(lf)
#(lf)newdata <- subset(dataset, Column1 == SearchValue )",
[dataset=#"Converted to Table"]),
    #"""newdata""" = #"Run R Script"{[Name="newdata"]}[Value]
in
    #"""newdata"""

Downside is that every time you change the param the script needs applying and the permissions confirming.

 

 

View solution in original post

3 REPLIES 3
stretcharm
Memorable Member
Memorable Member

Are you selecting using a Slicer? Slicers can work against r visualisations.

 

However they wont work against ther scripting in the Query editor.

Parameters could be used to filter data in the query editor r scripts.

 

 

 

Hi,

 

Thanks for your reply. 

Can you please explain this "Parameters could be used to filter data in the query editor r scripts."

 

Prashant

You can filter the data before passing it to r  

e.g. this filters from a testParam

 

let
    Source = List.Generate(()=>10, each _ > 0, each _ - 1),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Column1] = testParam),
    #"Run R Script" = R.Execute("# 'dataset' holds the input data for this script#(lf)#(lf)#(lf)newdata <- dataset",[dataset=#"Filtered Rows"]),
    #"""newdata""" = #"Run R Script"{[Name="newdata"]}[Value]
in
    #"""newdata"""

 

You can also change the code used for r based on params. 

e.g. this filters from a testParam by changing the r code.

 

let
    Source = List.Generate(()=>10, each _ > 0, each _ - 1),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Run R Script" = R.Execute("# 'dataset' holds the input data for this script
#(lf)
#(lf)SearchValue = '"&testParam&"'
#(lf)
#(lf)newdata <- subset(dataset, Column1 == SearchValue )",
[dataset=#"Converted to Table"]),
    #"""newdata""" = #"Run R Script"{[Name="newdata"]}[Value]
in
    #"""newdata"""

Downside is that every time you change the param the script needs applying and the permissions confirming.

 

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.