Forum Discussion
How to define a variable with existing measure with python script?
- Anonymous1 year ago
Hi MKMA,
Thank you for reaching out to the Microsoft Fabric Forum Community.
Python visuals in Power BI treat incoming data from the Fields/Values pane as a Pandas DataFrame, but measures behave differently than columns when passed into a Python visual. Measures Do not become standalone variables, they're aggregated and usually show up as part of a DataFrame row.
Use SUMMARIZE to simulate rows
create a table with measures as columns in Power BI using DAX like this:WaterfallTable =
SUMMARIZE(
'YourBaseTable',
'YourBaseTable'[Category],
"Target", [Month Target],
"Actual", [Month Actual],
)Then you can add this calculated table to the Python visual like a regular dataset, and reference like:
target = dataset['Target']
actual = dataset['Actual']
If you find this response helpful, please consider marking it as the accepted solution and giving it a thumbs-up to support others in the community.Thank you & regards,
Prasanna Kumar
Hi MKMA,
We wanted to kindly check in to see if everything is working as expected after trying the suggested solution. If there’s anything else we can assist with, please don’t hesitate to ask.
If the issue is resolved, we’d appreciate it if you could mark the helpful reply as Accepted Solution — it helps others who might face a similar issue.
Warm regards,
Prasanna Kumar