<?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: Performance issue DAX in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-issue-DAX/m-p/4303832#M170890</link>
    <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are some suggestions to optimize your query:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Using&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;TODAY()&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;multiple times can be inefficient. Store it in a variable and reuse it.&lt;/LI&gt;&lt;LI&gt;Instead of creating a calendar for the entire next year, limit it to the necessary date range.&lt;/LI&gt;&lt;LI&gt;Calculate&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;DaysSinceStart&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;only once and reuse it.&lt;/LI&gt;&lt;/OL&gt;&lt;H3&gt;&amp;nbsp;&lt;/H3&gt;&lt;P&gt;Here’s an optimized version (1) of your query, you could try this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SaleFromCurrentInventoryBalanceNY =
VAR CurrentDate = TODAY()
VAR InitialValue = [Opening Bal]
VAR CurrentYear = YEAR(CurrentDate)
VAR EndDate = DATE(CurrentYear + 1, 12, 31)
VAR DateRange = CALENDAR(CurrentDate, EndDate)
RETURN
SUMX(
    FILTER(
        ADDCOLUMNS(
            DateRange,
            "DaysSinceStart", DATEDIFF(CurrentDate, [Date], DAY),
            "DailyValueSub",
            IF(
                DATEDIFF(CurrentDate, [Date], DAY) &amp;lt; 'Day Range'[Day Range Value],
                DIVIDE(InitialValue, 'Day Range'[Day Range Value])
            )
        ),
        [Date] &amp;gt;= CurrentDate &amp;amp;&amp;amp; YEAR([Date]) = CurrentYear + 1
    ),
    [DailyValueSub]
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Version 2:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SaleFromCurrentInventoryBalanceNY =
VAR CurrentDate = TODAY()
VAR InitialValue = [Opening Bal]
VAR CurrentYear = YEAR(CurrentDate)
VAR EndDate = DATE(CurrentYear + 1, 12, 31)
VAR DateRange = CALENDAR(CurrentDate, EndDate)
VAR FilteredDates = 
    FILTER(
        DateRange,
        [Date] &amp;gt;= CurrentDate &amp;amp;&amp;amp; YEAR([Date]) = CurrentYear + 1
    )
VAR CalculatedValues = 
    ADDCOLUMNS(
        FilteredDates,
        "DaysSinceStart", DATEDIFF(CurrentDate, [Date], DAY),
        "DailyValueSub", 
        IF(
            DATEDIFF(CurrentDate, [Date], DAY) &amp;lt; 'Day Range'[Day Range Value],
            DIVIDE(InitialValue, 'Day Range'[Day Range Value])
        )
    )
RETURN
SUMX(
    CalculatedValues,
    [DailyValueSub]
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps!!&lt;/P&gt;&lt;P&gt;If this solved your problem, please accept it as a solution and a kudos!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;BR /&gt;Shahariar Hafiz&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Nov 2024 09:13:38 GMT</pubDate>
    <dc:creator>shafiz_p</dc:creator>
    <dc:date>2024-11-27T09:13:38Z</dc:date>
    <item>
      <title>Performance issue DAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-issue-DAX/m-p/4303761#M170887</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to optimize the performance of below query&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sale from Current Inventory Balance NY =&lt;BR /&gt;VAR CurrentDate =&lt;BR /&gt;TODAY ()&lt;BR /&gt;VAR InitialValue = [Opening Bal]&lt;BR /&gt;VAR CurrentYear =&lt;BR /&gt;YEAR ( CurrentDate )&lt;BR /&gt;RETURN&lt;BR /&gt;SUMX (&lt;BR /&gt;FILTER (&lt;BR /&gt;ADDCOLUMNS (&lt;BR /&gt;CALENDAR ( TODAY (), DATE ( YEAR ( TODAY () ) + 1, 12, 31 ) ),&lt;BR /&gt;"DaysSinceStart", DATEDIFF ( CurrentDate, [Date], DAY ),&lt;BR /&gt;"DailyValueSub",&lt;BR /&gt;IF (&lt;BR /&gt;DATEDIFF ( CurrentDate, [Date], DAY ) &amp;lt; 'Day Range'[Day Range Value],&lt;BR /&gt;DIVIDE ( [Opening Bal], 'Day Range'[Day Range Value] )&lt;BR /&gt;)&lt;BR /&gt;),&lt;BR /&gt;[Date] &amp;gt;= CurrentDate&lt;BR /&gt;&amp;amp;&amp;amp; YEAR ( [Date] )&lt;BR /&gt;= YEAR ( TODAY () ) + 1&lt;BR /&gt;),&lt;BR /&gt;[DailyValueSub]&lt;BR /&gt;)&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2024 08:39:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-issue-DAX/m-p/4303761#M170887</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-27T08:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: Performance issue DAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-issue-DAX/m-p/4303832#M170890</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are some suggestions to optimize your query:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Using&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;TODAY()&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;multiple times can be inefficient. Store it in a variable and reuse it.&lt;/LI&gt;&lt;LI&gt;Instead of creating a calendar for the entire next year, limit it to the necessary date range.&lt;/LI&gt;&lt;LI&gt;Calculate&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;DaysSinceStart&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;only once and reuse it.&lt;/LI&gt;&lt;/OL&gt;&lt;H3&gt;&amp;nbsp;&lt;/H3&gt;&lt;P&gt;Here’s an optimized version (1) of your query, you could try this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SaleFromCurrentInventoryBalanceNY =
VAR CurrentDate = TODAY()
VAR InitialValue = [Opening Bal]
VAR CurrentYear = YEAR(CurrentDate)
VAR EndDate = DATE(CurrentYear + 1, 12, 31)
VAR DateRange = CALENDAR(CurrentDate, EndDate)
RETURN
SUMX(
    FILTER(
        ADDCOLUMNS(
            DateRange,
            "DaysSinceStart", DATEDIFF(CurrentDate, [Date], DAY),
            "DailyValueSub",
            IF(
                DATEDIFF(CurrentDate, [Date], DAY) &amp;lt; 'Day Range'[Day Range Value],
                DIVIDE(InitialValue, 'Day Range'[Day Range Value])
            )
        ),
        [Date] &amp;gt;= CurrentDate &amp;amp;&amp;amp; YEAR([Date]) = CurrentYear + 1
    ),
    [DailyValueSub]
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Version 2:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SaleFromCurrentInventoryBalanceNY =
VAR CurrentDate = TODAY()
VAR InitialValue = [Opening Bal]
VAR CurrentYear = YEAR(CurrentDate)
VAR EndDate = DATE(CurrentYear + 1, 12, 31)
VAR DateRange = CALENDAR(CurrentDate, EndDate)
VAR FilteredDates = 
    FILTER(
        DateRange,
        [Date] &amp;gt;= CurrentDate &amp;amp;&amp;amp; YEAR([Date]) = CurrentYear + 1
    )
VAR CalculatedValues = 
    ADDCOLUMNS(
        FilteredDates,
        "DaysSinceStart", DATEDIFF(CurrentDate, [Date], DAY),
        "DailyValueSub", 
        IF(
            DATEDIFF(CurrentDate, [Date], DAY) &amp;lt; 'Day Range'[Day Range Value],
            DIVIDE(InitialValue, 'Day Range'[Day Range Value])
        )
    )
RETURN
SUMX(
    CalculatedValues,
    [DailyValueSub]
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps!!&lt;/P&gt;&lt;P&gt;If this solved your problem, please accept it as a solution and a kudos!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;BR /&gt;Shahariar Hafiz&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2024 09:13:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-issue-DAX/m-p/4303832#M170890</guid>
      <dc:creator>shafiz_p</dc:creator>
      <dc:date>2024-11-27T09:13:38Z</dc:date>
    </item>
  </channel>
</rss>

