<?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: Rank orders by value with multiple lines per order in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2049080#M46053</link>
    <description>&lt;P&gt;Yes, that is what I was looking for .. the issue I have now is that if I filter for a given product, say Product A, I would expected OrderNo 10, 9 and 4 to show up as Top 3 (given OrderNo 3 does not contain Product A), however this solution it is only showing my Orders 10 and 9.&lt;/P&gt;</description>
    <pubDate>Tue, 31 Aug 2021 13:59:55 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2021-08-31T13:59:55Z</dc:date>
    <item>
      <title>Rank orders by value with multiple lines per order</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2043772#M45899</link>
      <description>&lt;P&gt;Hello community, hope you can help me out ...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been trying to create a ranking of sales orders where some of them can have multiple line in the fact table since a given order can contain multiple products.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a really simple model, a fact table SalesOrders with two dimensions Date and Products, and two disconnected tables one for measures and one for rank grouping:&lt;/P&gt;&lt;P&gt;&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;This is what my fact table looks like:&lt;/P&gt;&lt;P&gt;&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;Then I created the following measures:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;(credit to Enterprise DNA since I took this formula from them ... )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;As a result of the measures above, I get the following working correctly:&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far so good ... the problem is what I want to add Products into the table or matrix and still see how the orders rank. As you can see in the table below, it is my DAX formula is ranking the orders within each product category / name:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img /&gt;&lt;P&gt;All that said, I really don't know how to modify my measure to have the ranking be like in the first set of tables but still show the product level data in the table... expecting something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The top 3 orders continue to be 10, 9 and 5, but I'm now showing the products each has with their values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope the explanation of my problem and what I've done so far was clear. I'm also adding the pbix file for this example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.dropbox.com/s/07jdemccvtyj944/sample%20for%20rank.pbix?dl=0" target="_self"&gt;Sample pbix file&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I really appreciate any help you can provide.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Esteban&lt;/P&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 28 Aug 2021 03:11:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2043772#M45899</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-08-28T03:11:04Z</dc:date>
    </item>
    <item>
      <title>Re: Rank orders by value with multiple lines per order</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2044090#M45906</link>
      <description>&lt;LI-CODE lang="csharp"&gt;Sales BG2 = 
var CurrentlyVisibleGroups = DISTINCT( 'Order Groups'[Group] )
var CurrentlyVisibleOrders = DISTINCT( SalesOrders[OrderNo] )
// Need to find all those orders
// from the visible ones that fall
// into any of the visible order groups.
var OrdersInCurrentlyVisibleGroups =
    CALCULATETABLE(
        var AllOrders = DISTINCT( SalesOrders[OrderNo] )
        return
        FILTER(
            CurrentlyVisibleOrders,
            var OrderRank = 
                RANKX(
                    AllOrders,
                    [Sales],,
                    DESC
                )
            var OrderGroup =
                MAXX(
                    // MAXX is OK here as the filer will
                    // return at most one row if everything
                    // is correctly set up.
                    FILTER(
                        'Order Groups',
                        'Order Groups'[Min] &amp;lt; OrderRank
                        &amp;amp;&amp;amp; 
                        OrderRank &amp;lt;= 'Order Groups'[Max]
                    ),
                    'Order Groups'[Group]
                )
            return
                OrderGroup in CurrentlyVisibleGroups
        ),
        // If you want to make this ranking independent of
        // Date as well, just use ALL instead of ALLEXCEPT.
        ALLEXCEPT( SalesOrders, 'Date' )
    )
var Result =
    CALCULATE(
        [Sales],
        OrdersInCurrentlyVisibleGroups
    )
return
    Result&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 28 Aug 2021 22:42:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2044090#M45906</guid>
      <dc:creator>daxer-almighty</dc:creator>
      <dc:date>2021-08-28T22:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: Rank orders by value with multiple lines per order</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2046613#M45988</link>
      <description>&lt;P&gt;Thank you very much for the quick reply&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="255913" data-lia-user-login="daxer-almighty" class="lia-mention lia-mention-user"&gt;daxer-almighty&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question about this solution ... I understand you first pull the CurrentlyVisibleOrders based on the filter context applied in the report, and then you iterate through AllOthers to rank them and return those that are within each group.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However if I change the filter context in my report, e.g. filtering only those orders that contain a given product, the formula still evaluates all orders and but only shows them if they have the product.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Esteban&lt;/P&gt;</description>
      <pubDate>Mon, 30 Aug 2021 15:39:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2046613#M45988</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-08-30T15:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: Rank orders by value with multiple lines per order</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2047583#M46005</link>
      <description>&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;is this what you want?&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 03:09:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2047583#M46005</guid>
      <dc:creator>wdx223_Daniel</dc:creator>
      <dc:date>2021-08-31T03:09:03Z</dc:date>
    </item>
    <item>
      <title>Re: Rank orders by value with multiple lines per order</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2049080#M46053</link>
      <description>&lt;P&gt;Yes, that is what I was looking for .. the issue I have now is that if I filter for a given product, say Product A, I would expected OrderNo 10, 9 and 4 to show up as Top 3 (given OrderNo 3 does not contain Product A), however this solution it is only showing my Orders 10 and 9.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 13:59:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2049080#M46053</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-08-31T13:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: Rank orders by value with multiple lines per order</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2049524#M46068</link>
      <description>&lt;P&gt;If you want to make the calculation also relative to the selected products, you have to change ALLEXCEPT( ..., 'Date' ) to ALLEXCEPT( ..., 'Date', 'Product' ) in the formula.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 17:58:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2049524#M46068</guid>
      <dc:creator>daxer-almighty</dc:creator>
      <dc:date>2021-08-31T17:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: Rank orders by value with multiple lines per order</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2049587#M46071</link>
      <description>&lt;P&gt;Thanks for your continued help&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="255913" data-lia-user-login="daxer-almighty" class="lia-mention lia-mention-user"&gt;daxer-almighty&lt;/a&gt;&amp;nbsp;. However when I do that, I get an odd behavior .. check image below:&lt;/P&gt;&lt;P&gt;&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;Thanks&lt;/P&gt;&lt;P&gt;Esteban&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 18:25:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2049587#M46071</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-08-31T18:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: Rank orders by value with multiple lines per order</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2050726#M46116</link>
      <description>&lt;P&gt;Anonymous&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can try this one. I suspect it's now doing what you wanted...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Sales BG2 = 
var CurrentlyVisibleGroups = DISTINCT( 'Order Groups'[Group] )
var CurrentlyVisibleOrders = DISTINCT( SalesOrders[OrderNo] )
var OrdersInCurrentlyVisibleGroups =
    CALCULATETABLE(
        var AllOrders = DISTINCT( SalesOrders[OrderNo] )
        return
        FILTER(
            CurrentlyVisibleOrders,
            var OrderRank = 
                RANKX(
                    AllOrders,
                    [Sales],,
                    DESC
                )
            var OrderGroup =
                MAXX(
                    FILTER(
                        'Order Groups',
                        'Order Groups'[Min] &amp;lt; OrderRank
                        &amp;amp;&amp;amp; 
                        OrderRank &amp;lt;= 'Order Groups'[Max]
                    ),
                    'Order Groups'[Group]
                )
            return
                OrderGroup in CurrentlyVisibleGroups
        ),
        ALLEXCEPT( SalesOrders, 'Date' ),
        // This directive should let you only rank
        // against orders that are relative to
        // all the visible products, visible
        // somewhere in your visual, not necessarily
        // just in the cell being evaluated.
        ALLSELECTED( 'Products' )
    )
var Result =
    CALCULATE(
        [Sales],
        OrdersInCurrentlyVisibleGroups
    )
return
    Result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bear in mind that 'Products' must be a dimension connected to your fact table 'SalesOrders'. And you should never slice in the UI by the columns of your fact tables. Only via dimensions. If you don't follow this rule... you'll be in trouble sooner or later. I tell you today.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 07:56:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2050726#M46116</guid>
      <dc:creator>daxer-almighty</dc:creator>
      <dc:date>2021-09-01T07:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Rank orders by value with multiple lines per order</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2051684#M46166</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="255913" data-lia-user-login="daxer-almighty" class="lia-mention lia-mention-user"&gt;daxer-almighty&lt;/a&gt;&amp;nbsp;that almost did it .. I think I got it fixed by changing the ALLEXCEPT( SalesOrders, 'Date' ) for ALLSELECTED( SalesOrders).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for all your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 14:54:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2051684#M46166</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-09-01T14:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: Rank orders by value with multiple lines per order</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2052261#M46197</link>
      <description>&lt;P&gt;Good you got it working exactly as you wanted. Sorry I was not able to address this problem immediately but I did not fully understand how this measure should behave in all possible contexts.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 20:24:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2052261#M46197</guid>
      <dc:creator>daxer-almighty</dc:creator>
      <dc:date>2021-09-01T20:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Rank orders by value with multiple lines per order</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2052265#M46198</link>
      <description>&lt;P&gt;You did great and put me on the right direction .. thanks for your help.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 20:29:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Rank-orders-by-value-with-multiple-lines-per-order/m-p/2052265#M46198</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-09-01T20:29:59Z</dc:date>
    </item>
  </channel>
</rss>

