<?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 Filtering calculation by first in partitioned group - Ways to optimize? in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Filtering-calculation-by-first-in-partitioned-group-Ways-to/m-p/912726#M8763</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="1522" data-lia-user-login="ImkeF" class="lia-mention lia-mention-user"&gt;ImkeF&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's somewhat difficult to provide sample data since everything I'm working with right now is classified... But as an example, let's say we have these tables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Base&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Case_Id&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; , ... Lots of unimportant columns&lt;/P&gt;&lt;P&gt;2) Task&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Task_Id&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;,Case_Id&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;,Task_Create_Date&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;,Tier 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both of these tables will contain transactional data, one record per Task in the Task table and one record per case for the Base table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a relationship between 1 and 2 on Case_Id. My desired end table would look like&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;FONT face="arial black,avant garde"&gt;Tier 1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/TD&gt;&lt;TD&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;FONT face="arial black,avant garde"&gt;Tasks&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/TD&gt;&lt;TD&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;FONT face="arial black,avant garde"&gt;Profiled&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Some_Category&lt;/TD&gt;&lt;TD&gt;800&lt;/TD&gt;&lt;TD&gt;300&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Some_OtherCategory&lt;/TD&gt;&lt;TD&gt;55&lt;/TD&gt;&lt;TD&gt;45&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Some_Final_Category&lt;/TD&gt;&lt;TD&gt;129&lt;/TD&gt;&lt;TD&gt;66&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Etc.&lt;/TD&gt;&lt;TD&gt;930&lt;/TD&gt;&lt;TD&gt;699&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The profiled column will show ONLY the count of the 'Most recent' tasks associated with the case, using the Task_Create_Date column as the indicator of what is most recent.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this helps. Thanks!&lt;/P&gt;</description>
    <pubDate>Mon, 27 Jan 2020 17:36:05 GMT</pubDate>
    <dc:creator>scriptpup</dc:creator>
    <dc:date>2020-01-27T17:36:05Z</dc:date>
    <item>
      <title>DAX Filtering calculation by first in partitioned group - Ways to optimize?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Filtering-calculation-by-first-in-partitioned-group-Ways-to/m-p/909784#M8651</link>
      <description>&lt;P&gt;This is a somewhat complex situation, but the basic need is pretty simple. As I said in the title, I'm looking to return a count based on the filtered partitions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IN SQL it looks like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SELECT
	[Tier 1]
	,COUNT(1) "Tasks"
FROM (
	SELECT
		tsk.[Tier 1]
		,ROW_NUMBER() OVER (PARTITION BY Case_ID ORDER BY CRT_DTS DESC) rw
	FROM someTasks tsk
) partitioned 
WHERE
	rw = 1
GROUP BY
	[Tier 1]&lt;/LI-CODE&gt;&lt;P&gt;Then if I want to change the date-range to show what the 'Latest' task tier was as of date yyyy-mm-dd, then I just add a WHERE in the inner query, simple.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In DAX I came up with the following:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SUMMARIZE (
        Task,
        Task[Tier 1],
        "Profiled", CALCULATE (
            COUNTROWS ( Task ),
            TREATAS (
                SELECTCOLUMNS (
                    SUMMARIZE (
                        Task,
                        Task[CASE_ID],
                        "MaxTask", CALCULATE (
                            MAX ( Task[TASK_ID] ),
                            FILTER ( Task, Task[CRT_DTS] = MAX ( Task[CRT_DTS] ) )
                        )
                    ),
                    "MaxTask", [MaxTask]
                ),
                Task[TASK_ID]
            )
        ),
        "Tasks", COUNTROWS ( Task )
    )&lt;/LI-CODE&gt;&lt;P&gt;This works, but is extremely slow (20 seconds to run in DAX studio) and seems inefficient, even to someone as inexperienced with DAX as I am.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a better, more optimized, way to do this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2020 16:32:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Filtering-calculation-by-first-in-partitioned-group-Ways-to/m-p/909784#M8651</guid>
      <dc:creator>scriptpup</dc:creator>
      <dc:date>2020-01-23T16:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Filtering calculation by first in partitioned group - Ways to optimize?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Filtering-calculation-by-first-in-partitioned-group-Ways-to/m-p/909798#M8653</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="157903" data-lia-user-login="scriptpup" class="lia-mention lia-mention-user"&gt;scriptpup&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a first step, please use ADDCOLUMNS for the column to add. Use SUMMARIZE only for the grouping:&amp;nbsp;&lt;A href="https://www.sqlbi.com/blog/marco/2012/09/04/optimize-summarize-with-addcolumns-in-dax-ssas-tabular-dax-powerpivot/" target="_blank" rel="noopener"&gt;https://www.sqlbi.com/blog/marco/2012/09/04/optimize-summarize-with-addcolumns-in-dax-ssas-tabular-dax-powerpivot/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Haven't studies the logic closely, but nested iterators can be a bit slow.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2020 16:50:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Filtering-calculation-by-first-in-partitioned-group-Ways-to/m-p/909798#M8653</guid>
      <dc:creator>ImkeF</dc:creator>
      <dc:date>2020-01-23T16:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Filtering calculation by first in partitioned group - Ways to optimize?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Filtering-calculation-by-first-in-partitioned-group-Ways-to/m-p/909928#M8656</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="1522" data-lia-user-login="ImkeF" class="lia-mention lia-mention-user"&gt;ImkeF&lt;/a&gt;, I changed the function to look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;EVALUATE
SUMMARIZE (
        Task,
        Task[Tier 1],
        "Profiled", CALCULATE (
            COUNTROWS ( Task ),
            TREATAS (
                SELECTCOLUMNS (
                    ADDCOLUMNS(SUMMARIZE (
                        Task,
                        Task[CASE_ID]),
                        "MaxTask", CALCULATE (
                            MAX ( Task[TASK_ID] ),
                            FILTER ( Task, Task[CRT_DTS] = MAX ( Task[CRT_DTS] ) )
                        )
                    ),
                    "MaxTask", [MaxTask]
                ),
                Task[TASK_ID]
            )
        ),
        "Tasks", COUNTROWS ( Task )
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I don't see any significant performance gain (Still takes on-average around 20 seconds)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;-- Edit, it's also now returning '1' for every row, so it's not doing the same thing/working correctly with ADDCOLUMNS, either.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2020 19:02:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Filtering-calculation-by-first-in-partitioned-group-Ways-to/m-p/909928#M8656</guid>
      <dc:creator>scriptpup</dc:creator>
      <dc:date>2020-01-23T19:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Filtering calculation by first in partitioned group - Ways to optimize?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Filtering-calculation-by-first-in-partitioned-group-Ways-to/m-p/909935#M8657</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="157903" data-lia-user-login="scriptpup" class="lia-mention lia-mention-user"&gt;scriptpup&lt;/a&gt; ,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;could you share some sample data please so I can understand what you're trying to achieve?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2020 19:03:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Filtering-calculation-by-first-in-partitioned-group-Ways-to/m-p/909935#M8657</guid>
      <dc:creator>ImkeF</dc:creator>
      <dc:date>2020-01-23T19:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Filtering calculation by first in partitioned group - Ways to optimize?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Filtering-calculation-by-first-in-partitioned-group-Ways-to/m-p/912726#M8763</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="1522" data-lia-user-login="ImkeF" class="lia-mention lia-mention-user"&gt;ImkeF&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's somewhat difficult to provide sample data since everything I'm working with right now is classified... But as an example, let's say we have these tables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Base&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Case_Id&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; , ... Lots of unimportant columns&lt;/P&gt;&lt;P&gt;2) Task&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Task_Id&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;,Case_Id&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;,Task_Create_Date&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;,Tier 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both of these tables will contain transactional data, one record per Task in the Task table and one record per case for the Base table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a relationship between 1 and 2 on Case_Id. My desired end table would look like&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;FONT face="arial black,avant garde"&gt;Tier 1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/TD&gt;&lt;TD&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;FONT face="arial black,avant garde"&gt;Tasks&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/TD&gt;&lt;TD&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;FONT face="arial black,avant garde"&gt;Profiled&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Some_Category&lt;/TD&gt;&lt;TD&gt;800&lt;/TD&gt;&lt;TD&gt;300&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Some_OtherCategory&lt;/TD&gt;&lt;TD&gt;55&lt;/TD&gt;&lt;TD&gt;45&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Some_Final_Category&lt;/TD&gt;&lt;TD&gt;129&lt;/TD&gt;&lt;TD&gt;66&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Etc.&lt;/TD&gt;&lt;TD&gt;930&lt;/TD&gt;&lt;TD&gt;699&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The profiled column will show ONLY the count of the 'Most recent' tasks associated with the case, using the Task_Create_Date column as the indicator of what is most recent.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this helps. Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 17:36:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Filtering-calculation-by-first-in-partitioned-group-Ways-to/m-p/912726#M8763</guid>
      <dc:creator>scriptpup</dc:creator>
      <dc:date>2020-01-27T17:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Filtering calculation by first in partitioned group - Ways to optimize?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Filtering-calculation-by-first-in-partitioned-group-Ways-to/m-p/913490#M8780</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="157903" data-lia-user-login="scriptpup" class="lia-mention lia-mention-user"&gt;scriptpup&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And what role does the "Tier" play?&lt;/P&gt;
&lt;P&gt;How about just creating some mockup data that return the result from the sample you've given?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 10:17:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Filtering-calculation-by-first-in-partitioned-group-Ways-to/m-p/913490#M8780</guid>
      <dc:creator>ImkeF</dc:creator>
      <dc:date>2020-01-28T10:17:13Z</dc:date>
    </item>
  </channel>
</rss>

