Setting up parameter's dynamic default based on RLS

I’m trying to set up my parameters dynamic default value. It seems that it only works based on users/groups. In my case, I have anonymous users accessing the dashboard where RLS is defined for the database. Is there anyway to configure default values for the parameter with RLS?

Hi @Siamak
based on what do you want the dynamic default set if your user is anonymous?
BR

For example, I have anonymous users a, b, and c accessing the dashboard. My parameter control contains items x, y, and z. Imagining below are the total count of each item for each user:

x y z
user a 100 200 300
user b 500 400 300
user c 200 300 100

I want to have the default value for each user be the item with maximum count, i.e. user a default should be z, user b should be x, and user c default should be y.

I have created a reference table with this maximum counts for each user, but since I’m using RLS and they are anonymous it doesn’t work when I set up dynamic defaults for my parameter.

Hi @Siamak
did you check

BR

Yes, I have set up RLS with tag-based rule and it’s working fine. My issue here is how to setup my parameters default value based on this RSL. I want to dynamically change my parameter’s default value depending on the user. And since it’s anonymous user, I can’t just make a list of users with default values. all I have is RLS.

Hi @Siamak
did you find a solution?
If not, maybe @duncan or @DylanM know something.
BR

1 Like

Thanks for the mention, @ErikG!

Hello @Siamak, unfortunately, with the way dynamic defaults work, having either UserName or GroupName is required for this functionality. If you wanted a way to accomplish something similar with anonymous users, it would require a rework of your dataset (or a new one for this use case).

Basically you would want your table formatted like this:
ReformatData

If you were able to use custom SQL to build a dataset where each user has a row based on the value category, then we can build an ifelse statement to handle this.

You would want a parameter linked to a control that would show “none” or “n/a” by default. Then a calculated field that would find the highest value for the user:
maxValueByUser = maxOver({value}, [{user}], PRE_AGG)

Then you can customize an ifelse statement to either return the row containing the max if “none” is the parameter, or filter to show the type based on the parameter value selected, else NULL. You would then utilize this calculated field rather than the original value field in your visuals, set to a custom filter, and exclude nulls.

ifelse({maxValueByUser} = {value} AND ${parameter} = "None", {value},
${parameter} = {type}, {value},
NULL)

Since we are using a maxOver function to check for the highest value, you may receive an error on this. If that is the case, use a sumOver function on value so you can compare them in the ifelse. valueByTypeAndUser = sumOver({value}, [{user}, {type}], PRE_AGG)

Then you should be able to check if {maxValueByUser} = {valueByTypeAndUser}

That is the only work-around that I think would be applicable for your situation. I will mark this as the solution for now, but if you have further questions, please let us know!