Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Filter a visual using the Role name

I have a table containing ORIGIN_COUNTRY and DESTINATION_COUNTRY.

I have created a role named "USA", which rule is:

ORIGIN_COUNTRY = "USA" || DESTINATION_COUNTRY = "USA".

 

Now, I create a visual where I want to see only the data where ORIGIN_COUNTRY = role name. I don't want to "hardcode" the rule, I want the filter to be based on the current role name. 

How can I do this?

12 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion
    I may be mis-understanding Anonymous but that is default behavior when RLS is implemented.
    • Anonymous's avatar
      Anonymous
      Not applicable

      Not really. Let's say that these are my data: 

      ORIGIN_COUNTRY | DESTINATION_COUNTRY

      USA                        | ITA

      USA                        | ITA

      JPN                        | USA

      ITA                         | USA

      AUA                       | JPN
      JPN                        | ITA

       

      I create the role "USA", which only shows records where ORIGIN_COUNTRY ="USA" || DESTINATION_COUNTRY="USA".

       

      When seeing the data as the role "USA", these are the records I can see:

      ORIGIN_COUNTRY | DESTINATION_COUNTRY

      USA                        | ITA

      USA                        | ITA

      JPN                        | USA

      ITA                         | USA

       

      Now, I want to create a row-card which only shows the records where ORIGIN_COUNTRY ="USA". How can apply this filter? When trying to do so, these are the possibilities I can filter ORIGIN_COUNTRY with: USA, JPN, ITA. I cannot "hard-select" the value "USA", because otherwise this won't work with the other roles, say JPN. There's no way to do a filter like: ORIGIN_COUNTRY = role_name?

      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion

        Anonymous That definitely clears up the confusion. Perhaps try this:

         

        1. Create a disconnected Countries table, just a list of countries. Put your row level security there. Then you could do this:

        2. Create a measure

        Measure = IF(ORIGIN_COUNTRY =MAX('Countries'[Country]) || DESTINATION_COUNTRY=MAX('Countries'[Country]),1,0)

        3. You can now do a page or report level filter for this to 1

        4. You can use the same technique at a visualization level for your other requirement

         

        Will try to think of other ideas.