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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
uk-roberto92
Frequent Visitor

Python visual: Using parameters from slicer

Hi,

 

I included a Python visual in a PBI Dashboard I am building.

In this PBI I have a selection page with a slicer that propagates to other pages in the report.

 

Is it possible to have a sort of @parameter in the python visual aligned to the slicer?

Ex:

slicer = @parameter (Group A, Group B, ...)

 

Python Visual built on:

df = df[Group] == @parameter ("Group A", "Group B", ...) 

 

Thanks

1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi @uk-roberto92 ,

 

Yes, you can absolutely use a slicer to control the data in a Python visual in Power BI. The integration is quite seamless. When you add a data field to the "Values" section of your Python visual's configuration, any slicer in your report that is based on that same field will automatically filter the pandas DataFrame that gets passed to your Python script.

 

You don't need to use a special @parameter or any placeholder syntax in your Python code. Power BI handles the filtering behind the scenes. If you have a slicer for a "Group" column, and the user selects "Group A", the DataFrame (which Power BI names dataset by default) available within your script will only contain rows where the "Group" column is "Group A". You can then write your Python code to work directly on this pre-filtered dataset.

 

For instance, if you've dragged your "Group" and "Sales" columns into the Python visual's values field, your script can be as simple as plotting the data it receives. The dataset DataFrame will change dynamically as the user interacts with the slicer, and the visual will update accordingly.

import matplotlib.pyplot as plt

# The 'dataset' DataFrame is already filtered by the slicer.
# There is no need to write additional filtering code.
# This example creates a simple bar plot of the data passed from Power BI.
dataset.plot(kind='bar', x='Group', y='Sales')

# Display the plot in the visual.
plt.show()

 

Best regards,

View solution in original post

2 REPLIES 2
DataNinja777
Super User
Super User

Hi @uk-roberto92 ,

 

Yes, you can absolutely use a slicer to control the data in a Python visual in Power BI. The integration is quite seamless. When you add a data field to the "Values" section of your Python visual's configuration, any slicer in your report that is based on that same field will automatically filter the pandas DataFrame that gets passed to your Python script.

 

You don't need to use a special @parameter or any placeholder syntax in your Python code. Power BI handles the filtering behind the scenes. If you have a slicer for a "Group" column, and the user selects "Group A", the DataFrame (which Power BI names dataset by default) available within your script will only contain rows where the "Group" column is "Group A". You can then write your Python code to work directly on this pre-filtered dataset.

 

For instance, if you've dragged your "Group" and "Sales" columns into the Python visual's values field, your script can be as simple as plotting the data it receives. The dataset DataFrame will change dynamically as the user interacts with the slicer, and the visual will update accordingly.

import matplotlib.pyplot as plt

# The 'dataset' DataFrame is already filtered by the slicer.
# There is no need to write additional filtering code.
# This example creates a simple bar plot of the data passed from Power BI.
dataset.plot(kind='bar', x='Group', y='Sales')

# Display the plot in the visual.
plt.show()

 

Best regards,

I didin't know this, but that makes sense!

Thx

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.