<?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: DAX For RLS in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-For-RLS/m-p/2367627#M60653</link>
    <description>&lt;P&gt;Thank you for your answer.&lt;/P&gt;&lt;P&gt;I'm a developer and used to algorithm logic. What I want could be done with this simple code :&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;foreach(dataRow in Data)
{
	foreach(struc in StructureTable)
	{
		if(dataRow.Left &amp;gt;= struc.Left &amp;amp;&amp;amp; dataRow.Right &amp;lt;= struc.Right)
			return true;
		else
			return false;
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;I know DAX doesn't work the same at all. But I thought there had to be a way to do it.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Mar 2022 14:39:22 GMT</pubDate>
    <dc:creator>Uhrond</dc:creator>
    <dc:date>2022-03-01T14:39:22Z</dc:date>
    <item>
      <title>DAX For RLS</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-For-RLS/m-p/2367568#M60648</link>
      <description>&lt;P&gt;Hello everyone, I need an expert in DAX because I have trouble understanding the logic of it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to implement the RLS in my Power BI report.&lt;/P&gt;&lt;P&gt;I have a nested set model as follow :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which is stored in a first table :&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then my data table that I want to filter also containing left and right values :&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So when "C" connects to the report ("C" comes from USERNAME() ), I want my data table to be filtered like this :&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because "C" has access to all data that has a left greater or equal than&amp;nbsp;&lt;STRONG&gt;3&lt;/STRONG&gt; and a right less or equal than&amp;nbsp;&lt;STRONG&gt;4&lt;/STRONG&gt;&lt;BR /&gt;AND the data that has a left greater or equal than&amp;nbsp;&lt;STRONG&gt;8&lt;/STRONG&gt; and a right less or equal than&amp;nbsp;&lt;STRONG&gt;13&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;This is what I want to convert to DAX.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this example I only have two lines for "C" but I can have more.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help, hope this is clear enough&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 14:20:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-For-RLS/m-p/2367568#M60648</guid>
      <dc:creator>Uhrond</dc:creator>
      <dc:date>2022-03-01T14:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: DAX For RLS</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-For-RLS/m-p/2367599#M60651</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="306001" data-lia-user-login="Uhrond" class="lia-mention lia-mention-user"&gt;Uhrond&lt;/a&gt;&amp;nbsp;I don't believe you have enough information in your tables to dynamically create/enforce the rules you have laid out. For example, there is nothing that indicates that the C rows should be less than versus greater than. Also, your comment about more than two rows is concerning because not sure how that would work.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 14:28:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-For-RLS/m-p/2367599#M60651</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2022-03-01T14:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: DAX For RLS</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-For-RLS/m-p/2367627#M60653</link>
      <description>&lt;P&gt;Thank you for your answer.&lt;/P&gt;&lt;P&gt;I'm a developer and used to algorithm logic. What I want could be done with this simple code :&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;foreach(dataRow in Data)
{
	foreach(struc in StructureTable)
	{
		if(dataRow.Left &amp;gt;= struc.Left &amp;amp;&amp;amp; dataRow.Right &amp;lt;= struc.Right)
			return true;
		else
			return false;
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;I know DAX doesn't work the same at all. But I thought there had to be a way to do it.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 14:39:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-For-RLS/m-p/2367627#M60653</guid>
      <dc:creator>Uhrond</dc:creator>
      <dc:date>2022-03-01T14:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: DAX For RLS</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-For-RLS/m-p/2374182#M61061</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="306001" data-lia-user-login="Uhrond" class="lia-mention lia-mention-user"&gt;Uhrond&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;According to your screenshot, I think the hierachy level in your data model will make calculations difficult.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;We can see that C is the parent in level 2 and C is also the child in level 3. This will confuse Power BI. Secondly, there are multiple ranges in C, I think it is better for you to expand the numeric range by create a new calculated table.&lt;/P&gt;
&lt;P&gt;Basic User Table:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Basic Data Table:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Now, let's create new User Table and Data table by Dax.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Expand User = 
GENERATE (
    SUMMARIZECOLUMNS (
        'Basic User'[Name],
        'Basic User'[UserName],
        'Basic User'[Left],
        'Basic User'[Right]
    ),
    GENERATESERIES (
        CALCULATE ( DISTINCT ( 'Basic User'[Left] ) ),
        CALCULATE ( DISTINCT ( 'Basic User'[Right] ) )
    )
)&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Expand Data = 
GENERATE (
    SUMMARIZECOLUMNS ( 'Basic Data'[Data], 'Basic Data'[Left], 'Basic Data'[Right] ),
    GENERATESERIES (
        CALCULATE ( DISTINCT ( 'Basic Data'[Left] ) ),
        CALCULATE ( DISTINCT ( 'Basic Data'[Right] ) )
    )
)&lt;/LI-CODE&gt;
&lt;P&gt;Build a relationship between [Value] column in two tables. Trun on "Apply security filter in both directions" due to many to mant relationship.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;We can get the user who login Power BI by USERNAME() or USERPRINCIPALNAME(). Here I suggest you use USERPRINCIPALNAME(), it will get email format username in both Power BI Desktop and Service.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Mange Roles:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Now let's see the report as &lt;A href="mailto:C@xxx.com" target="_blank"&gt;C@xxx.com&lt;/A&gt;. Result is as below.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Rico Zhou&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 06:14:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-For-RLS/m-p/2374182#M61061</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-03-04T06:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: DAX For RLS</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-For-RLS/m-p/2374489#M61081</link>
      <description>&lt;P&gt;Thanks for spending time on my problem.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 08:21:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-For-RLS/m-p/2374489#M61081</guid>
      <dc:creator>Uhrond</dc:creator>
      <dc:date>2022-03-04T08:21:46Z</dc:date>
    </item>
  </channel>
</rss>

