Forum Discussion

MKMA's avatar
MKMA
Frequent Visitor
1 year ago
Solved

How to define a variable with existing measure with python script?

Hello,  I want to create a custom waterfall chart. Found a beautiful piece of code on github for exactly this purpose.  Everytime I see python script used in a visualization the variables are alway...
  • Anonymous's avatar
    Anonymous
    1 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