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 following up to see if the solution provided was helpful in resolving your issue. Please feel free to let us know if you need any further assistance.
If the response addressed your query, kindly mark it as Accepted Solution and click Yes if you found it helpful — this will benefit others in the community as well.
Best regards,
Prasanna Kumar