<?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: Using a variable to determine sort order inside Rankx in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-variable-to-determine-sort-order-inside-Rankx/m-p/2224185#M52905</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="95682" data-lia-user-login="ebecerra" class="lia-mention lia-mention-user"&gt;ebecerra&lt;/a&gt; , better create two rank Var or measure with Asc and desc rank and use that &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example - All measures&lt;/P&gt;
&lt;P&gt;Rank1 = Rankx(Allselected(Sales), [Sales],,asc,dense)&lt;/P&gt;
&lt;P&gt;Rank2 = Rankx(Allselected(Sales), [Sales],,desc,dense)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if(selectedvalues(Table[Sort Order]) =1, [Rank1], [Rank2] )&lt;/P&gt;</description>
    <pubDate>Tue, 07 Dec 2021 02:48:53 GMT</pubDate>
    <dc:creator>amitchandak</dc:creator>
    <dc:date>2021-12-07T02:48:53Z</dc:date>
    <item>
      <title>Using a variable to determine sort order inside Rankx</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-variable-to-determine-sort-order-inside-Rankx/m-p/2224053#M52902</link>
      <description>&lt;P&gt;I'm using a slicer to select a "Sort type" for a visualization I have. Depending on what value is selected, I am planning to use that as the sort option for a RANKX function I have. For some reason when I use a variable to get the selected value (since I cannot see the table from inside the RANKX inner part) I get an error that says that it expects the ORDER argument to be 0/FALSE/DESC etc. The funny thing is that if I pass in a hardcoded value to my variable it works fine. Is there something I'm missing here in order to get it to work? Here is an example of the code I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt; &lt;SPAN&gt;TopOrBottom&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;SELECTEDVALUE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Top or Bottom'[Option]&lt;/SPAN&gt;&lt;SPAN&gt;)==&lt;/SPAN&gt;&lt;SPAN&gt;"Top"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;FALSE&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;TRUE&lt;/SPAN&gt;&lt;SPAN&gt;) // THIS DOES NOT WORK&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;VAR TopOrBottom = TRUE //THIS MAKES RANKX happy.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;...&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;RANKX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;ALLSELECTED&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;MyTable[pageTitle]&lt;/SPAN&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;[Total PageViews]&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;[Total PageViews]&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;TopOrBottom // This is where it complains that it needs a 0/1/TRUE/FALSE/ASC/DESC&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thanks in advanced for your help.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 07 Dec 2021 01:03:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-variable-to-determine-sort-order-inside-Rankx/m-p/2224053#M52902</guid>
      <dc:creator>ebecerra</dc:creator>
      <dc:date>2021-12-07T01:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using a variable to determine sort order inside Rankx</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-variable-to-determine-sort-order-inside-Rankx/m-p/2224185#M52905</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="95682" data-lia-user-login="ebecerra" class="lia-mention lia-mention-user"&gt;ebecerra&lt;/a&gt; , better create two rank Var or measure with Asc and desc rank and use that &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example - All measures&lt;/P&gt;
&lt;P&gt;Rank1 = Rankx(Allselected(Sales), [Sales],,asc,dense)&lt;/P&gt;
&lt;P&gt;Rank2 = Rankx(Allselected(Sales), [Sales],,desc,dense)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if(selectedvalues(Table[Sort Order]) =1, [Rank1], [Rank2] )&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2021 02:48:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-variable-to-determine-sort-order-inside-Rankx/m-p/2224185#M52905</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2021-12-07T02:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using a variable to determine sort order inside Rankx</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-variable-to-determine-sort-order-inside-Rankx/m-p/2224645#M52921</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="95682" data-lia-user-login="ebecerra" class="lia-mention lia-mention-user"&gt;ebecerra&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;We can achieve it by a little different method. By adding two rank functions in an if-else clause. The issue is RANKX function couldn't accept variables in the ORDER attribute.&lt;BR /&gt;&lt;BR /&gt;You can find the solution and measure formula below :&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;Neel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2021 07:17:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-variable-to-determine-sort-order-inside-Rankx/m-p/2224645#M52921</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-12-07T07:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using a variable to determine sort order inside Rankx</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-variable-to-determine-sort-order-inside-Rankx/m-p/2226044#M52999</link>
      <description>&lt;P&gt;Another option might be to flip the sign of the measure depending on Top/Bottom.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;VariableRank = 
VAR Sgn = IF ( SELECTEDVALUE ( 'Top or Bottom'[Option] ) = "Top", 1, -1 )
RETURN
    RANKX ( ALLSELECTED ( MyTable[pageTitle] ), Sgn * [Total PageViews] )&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 07 Dec 2021 17:18:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-variable-to-determine-sort-order-inside-Rankx/m-p/2226044#M52999</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2021-12-07T17:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using a variable to determine sort order inside Rankx</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-variable-to-determine-sort-order-inside-Rankx/m-p/2226210#M53008</link>
      <description>&lt;P&gt;Sweet! I liked this solution as it is simple enough to understand and for my particular scenario. Thanks a lot to everyone else for their soultions!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2021 19:00:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-variable-to-determine-sort-order-inside-Rankx/m-p/2226210#M53008</guid>
      <dc:creator>ebecerra</dc:creator>
      <dc:date>2021-12-07T19:00:18Z</dc:date>
    </item>
  </channel>
</rss>

