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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Guilherme8482
New Member

How to use dynamically filtered database in a python script

I'm doing an analysis that takes a subset available from my Power BI data source and generates a table using python (which performs complex calculations).

But my question is about how to bring filtered data into the Python script.

I'm using the query transformation, which has a Python script option to generate my calculation.

The problem is that when I use the filter panel (inside the panel), the Python script is never updated and the data is still wrong.

I tried to use Visual Python, but I don't want to see the Python graphs, I need to use the python data to then visualize it in the Power BI graphs.

 

I've looked for several solutions, but I can't get it to work.

 

For example, here is a code I need to run:

 

# The data must be filtered before applying my python script

import pandas as pd

dataset['SMA'] = dataset.VALUE.rolling(2, win_type='gaussian').sum(std=3)

# After that, I need to show using Power BI charts
 

 

4 REPLIES 4
v-kelly-msft
Community Support
Community Support

Hi  @Guilherme8482 ,

 

You could do the filtering in power query then load the data ,check the reference below:

https://docs.microsoft.com/en-us/power-query/filter-values

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Hi @v-kelly-msft ,

 

Thanks for the answer,

That's exactly what I'm doing, but the problem is that the power query never updated when using the python script.
Do you have any idea what I can do?

Hi  @Guilherme8482 ,

 

Is your issue solved?

If so,could you pls mark the reply as answered to close it?

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Hi  @Guilherme8482 ,

 

Even you click the "refresh" button,it cant be refreshed?

I have checked the reference,you could publish to Service and set a scheduled refresh for the dataset.Check below:

https://docs.microsoft.com/en-us/power-bi/connect-data/desktop-python-in-query-editor

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors