<?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: Optimize DAX Code in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3154454#M113100</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="443516" data-lia-user-login="ppm1" class="lia-mention lia-mention-user"&gt;ppm1&lt;/a&gt;&amp;nbsp;, first of all, thank you for the quick response. I am attaching a PBI file with Mock data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will try to describe the problem in more detail: My Fact table in the model contains transactions that represent visits of employees to various stores. My goal is to calculate a numerical distribution (number of stores where the product selected in the slicer is available) depending on the working day in the month (value in the columns of the matrix visual) with a time window of 42 days backwards from the selected working day. I only need the &lt;STRONG&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#FF0000"&gt;LAST VISIT TO THE STORE&lt;/FONT&gt;&lt;/STRONG&gt; in this context based on the criteria Working Day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mock Data PBI Link :&amp;nbsp;&lt;A href="https://www.dropbox.com/s/w9mmurd4xypmg7g/Mock%20PBI.pbix?dl=0" target="_blank" rel="noopener"&gt;https://www.dropbox.com/s/w9mmurd4xypmg7g/Mock%20PBI.pbix?dl=0https://www.dropbox.com/scl/fo/fdnqycmyseujmbekpab27/h?dl=0&amp;amp;rlkey=gld45txq515jujztu0s1l6a7c&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 26 Mar 2023 16:13:29 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-03-26T16:13:29Z</dc:date>
    <item>
      <title>Optimize DAX Code</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3154273#M113087</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;This fourmula count unique number of stores in time window of 42 days backward from the selected date in slicer.&lt;BR /&gt;However formula runs pretty slow when i change the name of product.&lt;BR /&gt;&lt;SPAN&gt;Could you please help me with optimizing my formula?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you in advance!&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;---------------------------------------------------------------------------------&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;ND Daily = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt; selDateEnd = &lt;/SPAN&gt;&lt;SPAN&gt;SELECTEDVALUE&lt;/SPAN&gt;&lt;SPAN&gt;('Working Days'[WorkingDate])&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt; selDateStart = selDateEnd - &lt;/SPAN&gt;&lt;SPAN&gt;42&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt; Summarized = &lt;/SPAN&gt;&lt;SPAN&gt;ALL&lt;/SPAN&gt;&lt;SPAN&gt;(WP_FactInput[Code],WP_FactInput[VisitTime])&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Var&lt;/SPAN&gt;&lt;SPAN&gt; tDinamic = &lt;/SPAN&gt;&lt;SPAN&gt;FILTER&lt;/SPAN&gt;&lt;SPAN&gt;(Summarized,WP_FactInput[VisitTime]&amp;lt;=selDateEnd&amp;amp;&amp;amp;WP_FactInput[VisitTime]&amp;gt;=selDateStart)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt; tUpper = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;SUMMARIZE&lt;/SPAN&gt;&lt;SPAN&gt;(tDinamic,WP_FactInput[Code],WP_FactInput[VisitTime])&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt; tLower = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;GROUPBY&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; tDinamic,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[Code],&lt;/SPAN&gt;&lt;SPAN&gt;"VisitTime"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;MAXX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;CURRENTGROUP&lt;/SPAN&gt;&lt;SPAN&gt;(),WP_FactInput[VisitTime]))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt; Final = &lt;/SPAN&gt;&lt;SPAN&gt;INTERSECT&lt;/SPAN&gt;&lt;SPAN&gt;(tUpper,tLower)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;return&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;DISTINCTCOUNT&lt;/SPAN&gt;&lt;SPAN&gt;(WP_FactInput[Code]),Final)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 26 Mar 2023 09:51:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3154273#M113087</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-03-26T09:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize DAX Code</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3154354#M113094</link>
      <description>&lt;P&gt;Based on your text description, why not just do a distinctcount of stores with a time intelligence expression to go back 42 days? Something like this.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;ND Daily =
VAR selDateEnd =
    SELECTEDVALUE ( 'Working Days'[WorkingDate] )
VAR selDateStart = selDateEnd - 42
RETURN
    CALCULATE (
        DISTINCTCOUNT ( WP_FactInput[Code] ),
        WP_FactInput[VisitTime] &amp;gt;= selDateStart
            &amp;amp;&amp;amp; WP_FactInput[VisitTime] &amp;lt;= selDateEnd
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If more complex than that, can you can post a link to a mock version of your pbix with enough data to see slowness (e.g., 1 sec or more)?&amp;nbsp;The community will likely provide alternate faster DAX.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pat&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2023 13:03:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3154354#M113094</guid>
      <dc:creator>ppm1</dc:creator>
      <dc:date>2023-03-26T13:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize DAX Code</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3154379#M113097</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please try&lt;/P&gt;
&lt;P&gt;ND Daily =&lt;BR /&gt;VAR selDateEnd =&lt;BR /&gt;SELECTEDVALUE ( 'Working Days'[WorkingDate] )&lt;BR /&gt;VAR selDateStart = selDateEnd - 42&lt;BR /&gt;VAR Summarized =&lt;BR /&gt;ALL ( WP_FactInput[Code], WP_FactInput[VisitTime] )&lt;BR /&gt;VAR tUpper =&lt;BR /&gt;FILTER (&lt;BR /&gt;Summarized,&lt;BR /&gt;WP_FactInput[VisitTime] &amp;lt;= selDateEnd&lt;BR /&gt;&amp;amp;&amp;amp; WP_FactInput[VisitTime] &amp;gt;= selDateStart&lt;BR /&gt;)&lt;BR /&gt;VAR tLower =&lt;BR /&gt;GROUPBY (&lt;BR /&gt;tUpper,&lt;BR /&gt;[Code],&lt;BR /&gt;"VisitTime", MAXX ( CURRENTGROUP (), WP_FactInput[VisitTime] )&lt;BR /&gt;)&lt;BR /&gt;VAR Final =&lt;BR /&gt;INTERSECT ( tUpper, tLower )&lt;BR /&gt;RETURN&lt;BR /&gt;COUNTROWS ( Final )&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2023 14:24:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3154379#M113097</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2023-03-26T14:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize DAX Code</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3154454#M113100</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="443516" data-lia-user-login="ppm1" class="lia-mention lia-mention-user"&gt;ppm1&lt;/a&gt;&amp;nbsp;, first of all, thank you for the quick response. I am attaching a PBI file with Mock data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will try to describe the problem in more detail: My Fact table in the model contains transactions that represent visits of employees to various stores. My goal is to calculate a numerical distribution (number of stores where the product selected in the slicer is available) depending on the working day in the month (value in the columns of the matrix visual) with a time window of 42 days backwards from the selected working day. I only need the &lt;STRONG&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#FF0000"&gt;LAST VISIT TO THE STORE&lt;/FONT&gt;&lt;/STRONG&gt; in this context based on the criteria Working Day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mock Data PBI Link :&amp;nbsp;&lt;A href="https://www.dropbox.com/s/w9mmurd4xypmg7g/Mock%20PBI.pbix?dl=0" target="_blank" rel="noopener"&gt;https://www.dropbox.com/s/w9mmurd4xypmg7g/Mock%20PBI.pbix?dl=0https://www.dropbox.com/scl/fo/fdnqycmyseujmbekpab27/h?dl=0&amp;amp;rlkey=gld45txq515jujztu0s1l6a7c&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2023 16:13:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3154454#M113100</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-03-26T16:13:29Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize DAX Code</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3154466#M113101</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;&amp;nbsp; , I tried this formula. Unfortunately, it's not working, filters from the dimensional tables don't propagate through the measure.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here's a link to mock data in the attachment : &lt;A href="https://www.dropbox.com/s/w9mmurd4xypmg7g/Mock%20PBI.pbix?dl=0" target="_blank"&gt;https://www.dropbox.com/s/w9mmurd4xypmg7g/Mock%20PBI.pbix?dl=0&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2023 16:10:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3154466#M113101</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-03-26T16:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize DAX Code</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3154477#M113103</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Please refer to attached sample file with the solution&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;ND daily = 
SUMX (
        CROSSJOIN ( VALUES ( DimEmployee[EMP Name] ), VALUES ( tSelectedDates[WorkingDate] ) ),
        VAR selDateEnd = tSelectedDates[WorkingDate]
        VAR selDateStart = selDateEnd - 42
        VAR Summarized = SUMMARIZE ( CALCULATETABLE ( FactND ), FactND[StoreID], FactND[VisitTime] )
        VAR tUpper = FILTER ( Summarized, FactND[VisitTime] &amp;lt;= selDateEnd &amp;amp;&amp;amp; FactND[VisitTime] &amp;gt;= selDateStart )
        VAR tLower = 
                GROUPBY (
                        tUpper,
                        FactND[StoreID],
                        "VisitTime", MAXX ( CURRENTGROUP(), FactND[VisitTime] )
                )

        VAR Final = INTERSECT ( tUpper, tLower )
        RETURN COUNTROWS ( Final )
)&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 26 Mar 2023 16:29:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3154477#M113103</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2023-03-26T16:29:50Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize DAX Code</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3154512#M113107</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;&amp;nbsp;thank you for your effort,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The formula works quite fast, but it gives a wrong result. It does not calculate the number of &lt;STRONG&gt;unique stores&lt;/STRONG&gt; visited within the selected period grouped by the last visit date like in the original attachment i have provided.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2023 17:34:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3154512#M113107</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-03-26T17:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize DAX Code</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3154843#M113127</link>
      <description>&lt;P&gt;I looked at this for a bit and ran out of time for tonight. Not sure I fully understand the logic of your existing measure. The measure below is much more performant (76 ms vs 3600 ms) and does what I think you are looking for but does not match all of your current values. If you know your current values are correct, perhaps this approach will give you some ideas to tweak it.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;ND daily 2 =
VAR selDateEnd =
    SELECTEDVALUE ( tSelectedDates[WorkingDate] )
VAR selDateStart = selDateEnd - 42
VAR Summarized =
    CALCULATETABLE (
        SUMMARIZE ( FactND, FactND[StoreID], "cMaxDate", MAX ( FactND[VisitTime] ) ),
        FactND[VisitTime] &amp;lt;= selDateEnd
            &amp;amp;&amp;amp; FactND[VisitTime] &amp;gt;= selDateStart
    )
RETURN
    CALCULATE (
        [BaseModelCount],
        TREATAS ( Summarized, FactND[StoreID], FactND[VisitTime] )
    )&lt;/LI-CODE&gt;&lt;P&gt;Pat&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 00:53:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3154843#M113127</guid>
      <dc:creator>ppm1</dc:creator>
      <dc:date>2023-03-27T00:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize DAX Code</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3155347#M113160</link>
      <description>&lt;P&gt;Anonymous&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;I tried hard to understand your your requirement and the numbers that are generated in your sample file and failed to understand what they really represent. Please clarify with some examples&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 07:33:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3155347#M113160</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2023-03-27T07:33:44Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize DAX Code</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3155486#M113174</link>
      <description>&lt;P&gt;This is an algorithm in steps:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;Depending on the date in the column in the matrix visual, filter the Fact table and find the last visit for each store (StoreID, SBO column in the dimEmployee table) for a period of 42 days prior to that date.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Count all unique store numbers for a specific product that I select in the slicer.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;The problem arises because in one month, there may be multiple visits to one store, and not all products may be available during each visit. I only need rows with the last visit.&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Here is link for excel file:&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.dropbox.com/sh/31t6kwe0c885wjt/AAA6R3sYvZr4SuKduYYSwTiBa?dl=0" target="_blank"&gt;https://www.dropbox.com/sh/31t6kwe0c885wjt/AAA6R3sYvZr4SuKduYYSwTiBa?dl=0&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 08:25:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3155486#M113174</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-03-27T08:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize DAX Code</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3155745#M113194</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="443516" data-lia-user-login="ppm1" class="lia-mention lia-mention-user"&gt;ppm1&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;BR /&gt;&lt;SPAN&gt;I modified your formula to return the desired result, the trick is in using returning all rows before grouping by the maximum date.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;ND daily 2 = 
VAR selDateEnd =
    SELECTEDVALUE ( tSelectedDates[WorkingDate] )
VAR selDateStart = selDateEnd - 42
VAR Summarized =
    GROUPBY(
       FILTER(ALLEXCEPT(FactND,FactND[ProductID]),FactND[VisitTime]&amp;lt;=selDateEnd&amp;amp;&amp;amp;FactND[VisitTime]&amp;gt;=selDateStart),
       FactND[StoreID],"MaxVisitDate",MAXX(CURRENTGROUP(),FactND[VisitTime]))
  
RETURN
    CALCULATE (
        [BaseModelCount],
        TREATAS ( Summarized, FactND[StoreID], FactND[VisitTime] )
    )&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 27 Mar 2023 10:37:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3155745#M113194</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-03-27T10:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize DAX Code</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3158433#M113355</link>
      <description>&lt;P&gt;Still trying to understand the needed logic and made a page to focus on one result from original matrix. For Product 19, Emp 125, and a 42 day range ending on March 1st (your first column), your measure shows a value of 2. Should the last row below on the 18th be excluded? If not, pls clarify how to count the stores to get 2. Since you are looking for max dates, why doesn't a simple distinct count of stores meet the need?&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;Pat&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 12:23:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Code/m-p/3158433#M113355</guid>
      <dc:creator>ppm1</dc:creator>
      <dc:date>2023-03-28T12:23:03Z</dc:date>
    </item>
  </channel>
</rss>

