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,
Just a gentle reminder — has your issue been resolved? If so, we’d be grateful if you could mark the solution that worked as Accepted Solution, or feel free to share your own if you found a different fix.
This not only closes the loop on your query but also helps others in the community solve similar issues faster.
Thank you for your time and feedback!
Best,
Prasanna Kumar