Forum Discussion

AldoOlmos239's avatar
AldoOlmos239
Regular Visitor
2 years ago

It is possible to read a slicer value from a python script?

Hi there everyone!
I want to know if it is possible to read the selected value of a slicer in a Python Script.

Right now everytime I want to retrieve some data according the sales of "x" or "y" product category I need to change manually that value in a variable to search trought a data set.

I have been searching but havent found anything useful. Hope that you can help me!


1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi AldoOlmos239 ,

     

    1. Create a parameter in Power BI that will hold the value of the slicer. You can do this by going to the “Modeling” tab and clicking on “New Parameter”. Give the parameter a name and set the data type to “Text”.
    2. Add a slicer to your report that is connected to the column you want to filter on.
    3. In your Python script, you can reference the parameter you created in step 1 using the library.
    report = Report("https://app.powerbi.com/reportEmbed?reportId=12345")
    parameter = report.get_parameters_by_name("Parameter1")[0]
    selected_value = parameter.current_value

    You can refer to the following post that may be helpful to you:

    Slicers as input for Python script - Microsoft Fabric Community

     

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly.