Forum Discussion

EmiOB's avatar
EmiOB
Regular Visitor
1 year ago
Solved

Can't create a text parameter

I'm trying to find a way to pass the user selections from 2 different slicers as inputs to some to create custom python visuals.  I found this answer (It is possible to read a slicer value from a pyt...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Thanks for the reply from 123abc , please allow me to provide another insight:

    Hi, EmiOB 
    Thanks for reaching out to the Microsoft fabric community forum.

    Regarding the issue you raised, my solution is as follows:

    You can try combining the parameter field with the SELECTEDVALUE() function. Here’s how you can do it:

    Use report readers to change visuals (preview) - Power BI | Microsoft Learn
    For example, my sample data includes multiple columns:

    1. Create two parameter fields as you need two slicers.

    2.Since directly applying the SELECTEDVALUE() function to the parameter column may cause errors, it is recommended to create a calculated column for each parameter:

    3.Create a measure to clearly identify the selected column name:

    selection1 = SELECTEDVALUE('Parameter2'[Column n])
    selection2 = SELECTEDVALUE('Parameter'[Column n1])

    4. Use the two parameters and the two measures as inputs in the Python custom visual object:

    5. Use the loc method to directly select the column..Here is my test Python code:

    import matplotlib.pyplot as plt
    # Paste or type your script code here:
    dataset['Selected1'] = dataset.apply(lambda row: row.loc[row['selection1']], axis=1)
    dataset['Selected2'] = dataset.apply(lambda row: row.loc[row['selection2']], axis=1)
    # Create a figure and a subplot
    fig, ax = plt.subplots(figsize=(8, 3)) # Set the size of the chart
    # Hide the default x-axis and y-axis
    ax.xaxis.set_visible(False)
    ax.yaxis.set_visible(False)
    ax.set_frame_on(False)
    # Create a table, displaying only the Selected1 and Selected2 columns
    table = ax.table(cellText=dataset[['Selected1', 'Selected2']].values, colLabels=['Selected1', 'Selected2'], cellLoc='center', loc='center')
    # Adjust the table style
    table.auto_set_font_size(False)
    table.set_fontsize(10)
    table.scale(1.2, 1.2)
    # Display the chart
    plt.show()
    

    6.Here's my final result, which I hope meets your requirements.

     

    Please find the attached pbix relevant to the case.

     

    Best Regards,

    Leroy Lu

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