Forum Discussion
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 pytho... - Microsoft Fabric Community) that suggests creating a new text parameter to store the user inputs.
However when I go to Modeling > New Parameter, I don't have a Text option under data type, only Whole number, Decimal number and Fixed decimal number. I've googled around some tutorials on how to do this, but none have helped. Some have a drop down menu by the New Parameter button which I don't have, and others say just select text under the Data type dropdown.
Any help with how to do this (or a simpler way to pass user selected values into the python code for a visual) would be greatly apreciated.
- Anonymous1 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.
8 Replies
- 123abcCommunity Champion
Please follow belo community soluiton: Hope This will help you;
Solved: Pass a text parameter in report - Microsoft Fabric Community
I hope this helps!
If you found this answer helpful:Mark it as the solution to help others find it faster.
Give it a kudo to show your appreciation!
Thank you for being an awesome community member!- EmiOBRegular Visitor
I have about 90 different options, and I need the user to select 2 (probably from 2 separate slicers, to be the x and y axis of a scatter plot). This solution suggests I will manually need to put each option into something like an IF statement, which isn't really practical.
- AnonymousNot applicable
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.