<?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: Help needed to optimize DAX query in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-needed-to-optimize-DAX-query/m-p/4043744#M160383</link>
    <description>&lt;P&gt;Hi,&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="771686" data-lia-user-login="Burtoninlondon" class="lia-mention lia-mention-user"&gt;Burtoninlondon&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am glad to help you.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;According to your description, you want&amp;nbsp;help needed to optimize DAX query?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I understand you correctly, then you can refer to my solution.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;You can remove unnecessary data or optimize your data structure to speed up queries.&amp;nbsp;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL start="2"&gt;
&lt;LI&gt;Regarding your two DAX formulas, I have optimized them as follows:&amp;nbsp;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Running Total =
VAR RunningTotal =
    SUMX (
        FILTER (
            ALL ( 'Strategy data' ),
            'Strategy data'[Date] &amp;lt;= MAX ( 'Strategy data'[Date] )
        ),
        'Strategy data'[Profit]
    )
RETURN
    RunningTotal&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Max Drawdown =
VAR RunningTotal = [Running Total]
VAR RollingMax =
    CALCULATE (
        MAXX ( VALUES ( 'Strategy data'[Date] ), [Running Total] ),
        FILTER (
            ALL ( 'Strategy data'[Date] ),
            'Strategy data'[Date] &amp;lt;= MAX ( 'Strategy data'[Date] )
        )
    )
RETURN
    RunningTotal - RollingMax
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can refer to the official documentation to optimize your DAX:&lt;A href="https://learn.microsoft.com/en-us/dax/dax-function-reference" target="_blank"&gt;DAX function reference - DAX | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;Fen Ling,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;If this post &lt;STRONG&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;/STRONG&gt;, then please consider &lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt; to help the other members find it more quickly.&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jul 2024 07:24:58 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-07-16T07:24:58Z</dc:date>
    <item>
      <title>Help needed to optimize DAX query</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-needed-to-optimize-DAX-query/m-p/4042015#M160278</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am a relatively new user of PowerBI, PowerQuery, DAX, etc. and have developed my dashboard with the help of this community. I'm saying this to provide an indication of my experience when you read this post.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My dashboard is simple and I intend to use it to visualise the performance of a portfolio of automated strategies trading on the US stock market. The data set comprises 17 individual excel files which I've combined in PowerQuery to form a single table in the PowerBI model, there is approximately 6,800 rows in this master table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The dashboard works well and suits my needs however there is one DAX query which returns a "Resources Exceeded" error. To get this DAX query to run without an error I need to increase the memory in the 'Query-limit simulations' Report settings option to 16GB however the time taken to run this DAX query is long. The image below is from the PowerBI Performance Analyzer.&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;The query I have the problem with is called Max. Drawdown which I have established as a measure in my powerBI model. The DAX formula is as below:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Max Drawdown = 
MINX(
    VALUES('Strategy data'[Date]),
    VAR _p =
        WINDOW(1, ABS, 0, REL, ORDERBY( 'Strategy data'[Date] ) )
    RETURN
        [Running Total] - MAXX( _p, [Running Total] )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It refers to another measure called 'Running Total' which calculates the cumulative total by time.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Running Total = 
CALCULATE (
    SUM('Strategy data'[Profit]),
    FILTER ( ALLSELECTED('Strategy data'), 'Strategy data'[Date] &amp;lt;= MAX ( 'Strategy data'[Date] ) )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a date slicer on my PowerBI dashboard which I can use to filter the data by date and I also have a Strategy slicer which I can use to filter by each of my automated trading strategies.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am reaching out to the community for support on how I can optimize this DAX query. Is there a more efficient way to structure the calculation? Can the calculation be performed closer to the data source (noting that I need the functionality of the slicers on the Power BI dashboard)? Or is there an alternative way to achieve what I need?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have uploaded my PowerBI dashboard to wetransfer should you want to view the file...&lt;A href="https://we.tl/t-2oqvUxv0YC" target="_self"&gt;PBIX file&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help you can provide will be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Neil&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2024 08:21:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-needed-to-optimize-DAX-query/m-p/4042015#M160278</guid>
      <dc:creator>Burtoninlondon</dc:creator>
      <dc:date>2024-07-15T08:21:30Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed to optimize DAX query</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-needed-to-optimize-DAX-query/m-p/4043744#M160383</link>
      <description>&lt;P&gt;Hi,&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="771686" data-lia-user-login="Burtoninlondon" class="lia-mention lia-mention-user"&gt;Burtoninlondon&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am glad to help you.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;According to your description, you want&amp;nbsp;help needed to optimize DAX query?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I understand you correctly, then you can refer to my solution.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;You can remove unnecessary data or optimize your data structure to speed up queries.&amp;nbsp;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL start="2"&gt;
&lt;LI&gt;Regarding your two DAX formulas, I have optimized them as follows:&amp;nbsp;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Running Total =
VAR RunningTotal =
    SUMX (
        FILTER (
            ALL ( 'Strategy data' ),
            'Strategy data'[Date] &amp;lt;= MAX ( 'Strategy data'[Date] )
        ),
        'Strategy data'[Profit]
    )
RETURN
    RunningTotal&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Max Drawdown =
VAR RunningTotal = [Running Total]
VAR RollingMax =
    CALCULATE (
        MAXX ( VALUES ( 'Strategy data'[Date] ), [Running Total] ),
        FILTER (
            ALL ( 'Strategy data'[Date] ),
            'Strategy data'[Date] &amp;lt;= MAX ( 'Strategy data'[Date] )
        )
    )
RETURN
    RunningTotal - RollingMax
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can refer to the official documentation to optimize your DAX:&lt;A href="https://learn.microsoft.com/en-us/dax/dax-function-reference" target="_blank"&gt;DAX function reference - DAX | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;Fen Ling,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;If this post &lt;STRONG&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;/STRONG&gt;, then please consider &lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt; to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2024 07:24:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-needed-to-optimize-DAX-query/m-p/4043744#M160383</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-07-16T07:24:58Z</dc:date>
    </item>
  </channel>
</rss>

