<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Creating a filter based on USERPRINCIPALNAME in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Creating-a-filter-based-on-USERPRINCIPALNAME/m-p/2443780#M65521</link>
    <description>&lt;P&gt;@Anonymous , You can create a measure as only one value would be there for use login(userprincipalname )&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Apr 2022 14:39:17 GMT</pubDate>
    <dc:creator>amitchandak</dc:creator>
    <dc:date>2022-04-07T14:39:17Z</dc:date>
    <item>
      <title>Creating a filter based on USERPRINCIPALNAME</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Creating-a-filter-based-on-USERPRINCIPALNAME/m-p/2441815#M65421</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I have following user table and I have applied Row Level Security based on Organisational Hierarchy. I would like to create a slicer based on logged in user as if logged in person's state is same as user's state then "Domestic" else "International". However, I can't use&amp;nbsp;USERPRINCIPALNAME in calculated columns/tables. so any idea if that's doable? I have attached .pbix file as well. thanks&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Users.PNG" style="width: 444px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/695988i5C6DA9559983CF53/image-size/large?v=v2&amp;amp;px=999" role="button" title="Users.PNG" alt="Users.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;PATHCONTAINS(Users[Path_Func],LOOKUPVALUE(Users[user ID],Users[email],USERPRINCIPALNAME()))&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RowLevelSecurity.PNG" style="width: 973px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/695987iEA3B7EF27365FFF2/image-size/large?v=v2&amp;amp;px=999" role="button" title="RowLevelSecurity.PNG" alt="RowLevelSecurity.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Formula not working beacuse we&amp;nbsp;can't use&amp;nbsp;USERPRINCIPALNAME in calculated columns/tables.&lt;/U&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Domestic/Interstate = &lt;/SPAN&gt;&lt;SPAN&gt;IF&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;Users[user State]&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;LOOKUPVALUE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;Users[user State]&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;Users[email]&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;USERPRINCIPALNAME&lt;/SPAN&gt;&lt;SPAN&gt;()),&lt;/SPAN&gt;&lt;SPAN&gt;"Domestic"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;"Interstate"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;U&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="error.PNG" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/695990iA577E1FF54475E89/image-size/large?v=v2&amp;amp;px=999" role="button" title="error.PNG" alt="error.PNG" /&gt;&lt;/span&gt;&lt;/U&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 00:10:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Creating-a-filter-based-on-USERPRINCIPALNAME/m-p/2441815#M65421</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-04-07T00:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a filter based on USERPRINCIPALNAME</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Creating-a-filter-based-on-USERPRINCIPALNAME/m-p/2443780#M65521</link>
      <description>&lt;P&gt;@Anonymous , You can create a measure as only one value would be there for use login(userprincipalname )&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 14:39:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Creating-a-filter-based-on-USERPRINCIPALNAME/m-p/2443780#M65521</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2022-04-07T14:39:17Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a filter based on USERPRINCIPALNAME</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Creating-a-filter-based-on-USERPRINCIPALNAME/m-p/2445752#M65620</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you've observed, &lt;STRONG&gt;USERPRINCIPALNAME()&lt;/STRONG&gt; cannot be used in calculated columns. This is because calculated columns have to be processed (and therefore fixed in value) before any individual user queries the dataset and RLS is applied.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So any possible solution would have to involve either:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Additional RLS filters&lt;/LI&gt;
&lt;LI&gt;Measures (which could be extended to Calculation Groups)&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;I couldn't see your attached PBIX, but&amp;nbsp;I have attached a PBIX with a couple of ideas using these two options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;1. Addional RLS filters&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;You could create an additional State table that contains every possible state along with both possible values of Domestic/Interstate:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="OwenAuger_0-1649413918293.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/697041i7111E4507FCEC90F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="OwenAuger_0-1649413918293.png" alt="OwenAuger_0-1649413918293.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The State column of this table is then related either directly or indirectly (via bridge table) to the Users[user State] column.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="OwenAuger_2-1649414073728.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/697044i6279F3C3D09CCF57/image-size/medium?v=v2&amp;amp;px=400" role="button" title="OwenAuger_2-1649414073728.png" alt="OwenAuger_2-1649414073728.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, to ensure each State is correctly classified when a particular user queries the dataset, create an RLS filter on the State table, that "selects" the correct classification for each State based on USERPRINCIPALNAME().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;VAR CurrentUserState =
    LOOKUPVALUE (
        Users[user State],
        Users[email],
        USERPRINCIPALNAME()
    )
RETURN
    IF (
        'State'[State] = CurrentUserState,
        'State'[Domestic/Interstate] = "Domestic",
        'State'[Domestic/Interstate] = "Interstate"
    )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can then filter on the column &lt;STRONG&gt;State[Domestic/Interstate]&lt;/STRONG&gt;, which will propogate to the &lt;STRONG&gt;Users&lt;/STRONG&gt; table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2.&amp;nbsp;Measures (which could be extended to Calculation Groups)&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;You could alternatively create a segmentation table called &lt;STRONG&gt;Domestic/Interstate Segment&lt;/STRONG&gt; containing just Domestic/Interstate, and create a Calculation Group which applies segmentation to any measure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First create &lt;STRONG&gt;Domestic/Interstate Segmentation&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="OwenAuger_3-1649414281696.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/697046i0ED8CE2DB42ECB77/image-size/medium?v=v2&amp;amp;px=400" role="button" title="OwenAuger_3-1649414281696.png" alt="OwenAuger_3-1649414281696.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Then create a Calculation Group in Tabular Editor with a single Calculation Item that applies the segmentation&lt;BR /&gt;(I created the Calculation Group&amp;nbsp;&lt;STRONG&gt;'Segmentation Calculation Group'[Segmentation Rule]&amp;nbsp;&lt;/STRONG&gt;with single Calculation Item &lt;STRONG&gt;"Domestic/Interstate Segmentation"&lt;/STRONG&gt;.):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;VAR CurrentUserState =
    LOOKUPVALUE (
        Users[user State],
        Users[email],
        USERPRINCIPALNAME()
    )
VAR StateFilter =
    GENERATE (
        VALUES ( 'Domestic/Interstate Segment'[Domestic/Interstate] ),
        FILTER (
            VALUES ( Users[user State] ),
            IF (
                Users[user State] = CurrentUserState    ,
                'Domestic/Interstate Segment'[Domestic/Interstate] = "Domestic",
                'Domestic/Interstate Segment'[Domestic/Interstate] = "Interstate"
            )
        )
    )
                
RETURN
    CALCULATE (
        SELECTEDMEASURE (),
        KEEPFILTERS ( StateFilter )
    )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="OwenAuger_4-1649414378464.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/697047iAE64CE1ECC07FD10/image-size/large?v=v2&amp;amp;px=999" role="button" title="OwenAuger_4-1649414378464.png" alt="OwenAuger_4-1649414378464.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Then in the report, apply the single Calculation Item as a filter, and use &lt;STRONG&gt;Domestic/Interstate Segment[Domestic/Interstate]&lt;/STRONG&gt; to filter/group in visuals.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Result&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;As long as USERPRINCIPALNAME() corresponds to one of the users listed, and an appropriate measure is used in visuals, then both methods give expected results. For example, if you view as &lt;STRONG&gt;user1@xyz.com&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="OwenAuger_7-1649414854576.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/697050iE7FF7430E805E09B/image-size/large?v=v2&amp;amp;px=999" role="button" title="OwenAuger_7-1649414854576.png" alt="OwenAuger_7-1649414854576.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If for some reason RLS didn't apply (such as the report viewer having higher than Viewer permissions in the Workspace), the first method could produce odd results, and might require a bit more thought.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well, those are some ideas anyway, and there are undoubtedly variations of these that would also work &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do either of those methods work in your model?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Owen&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2022 10:54:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Creating-a-filter-based-on-USERPRINCIPALNAME/m-p/2445752#M65620</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2022-04-08T10:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a filter based on USERPRINCIPALNAME</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Creating-a-filter-based-on-USERPRINCIPALNAME/m-p/2448279#M65802</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/6799"&gt;@OwenAuger&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I really appreciate your time and help on that query. I have applied solution number-1 to my actual model and it is working as expected. I haven't had a chance to apply second solution yet, but will definetely try that one as well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks again&lt;/P&gt;&lt;P&gt;Great response!&lt;/P&gt;&lt;P&gt;Duygu&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2022 04:38:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Creating-a-filter-based-on-USERPRINCIPALNAME/m-p/2448279#M65802</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-04-11T04:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a filter based on USERPRINCIPALNAME</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Creating-a-filter-based-on-USERPRINCIPALNAME/m-p/3505133#M134470</link>
      <description>&lt;P&gt;Thank you so much &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/6799"&gt;@OwenAuger&lt;/a&gt;&amp;nbsp;for taking the time to write such detailed explanations.&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;I've used solution n.2, it works beautifully.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 16:39:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Creating-a-filter-based-on-USERPRINCIPALNAME/m-p/3505133#M134470</guid>
      <dc:creator>marion1</dc:creator>
      <dc:date>2023-10-30T16:39:52Z</dc:date>
    </item>
  </channel>
</rss>

