<?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 Query in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Query/m-p/4134140#M164209</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="441219" data-lia-user-login="cchilton" class="lia-mention lia-mention-user"&gt;cchilton&lt;/a&gt;&amp;nbsp;- You need to un-pivot the table that has your data in them so that you end up with 1 column each for the Actual and Targets and an additional column that defines whether those figures are CarInv, ToyInv or BearInv etc (call this measure name).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you only need to create one DAX measure which will be&amp;nbsp;&lt;SPAN&gt;DIVIDE&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;( KpiActual - KpiTarget, KpiTarget ). A slicer for the measure name column will filter out all the rows &amp;amp; values that are not needed for the calculation.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I wouldnt try to solve this with DAX it's a modelling issue. Here is an article I wrote on un-pivoting data:&amp;nbsp;&lt;A href="https://triangle.im/power-bi-mistake-5-why-pivoted-data-leads-to-power-bi-pain/" target="_blank" rel="noopener"&gt;https://triangle.im/power-bi-mistake-5-why-pivoted-data-leads-to-power-bi-pain/&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If this helps, please mark it as a solution for others - it helps with visibility.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Sep 2024 21:26:56 GMT</pubDate>
    <dc:creator>mark_endicott</dc:creator>
    <dc:date>2024-09-04T21:26:56Z</dc:date>
    <item>
      <title>Optimize DAX Query</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Query/m-p/4134116#M164208</link>
      <description>&lt;P&gt;I am calculating the percentage a user is above or below target. Below are example measures that mimick what I am doing in Power BI. Is there any way I can avoid using a SWITCH statement in averageKPI and targetKPI? I have about 60 variables for these SWITCH statements. The targetPct measure is being used in a card. That card takes 5+ seconds to load and even longer where it is embedded in our web application.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;What I tried:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;averageKPI =&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;// VAR metric = SELECTEDVALUE('values'[value_fields])&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;// RETURN &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;// LOOKUPVALUE(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;// &amp;nbsp; &amp;nbsp; TEST_Measure_Lookup_Actual[Measures], &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;// &amp;nbsp; &amp;nbsp; TEST_Measure_Lookup_Actual[value_fields], metric&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;// )&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;What I am currently doing:&amp;nbsp;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;averageKPI =&lt;BR /&gt;VAR metric =&lt;BR /&gt;SELECTEDVALUE ( 'values'[value_fields] )&lt;BR /&gt;VAR carInv = [carInv_measure]&lt;BR /&gt;VAR toyInv = [toyInv_measure]&lt;BR /&gt;VAR bearInv = [bearInv_measure]&lt;BR /&gt;etc..&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;VAR RESULT =&lt;BR /&gt;SWITCH (&lt;BR /&gt;TRUE (),&lt;BR /&gt;metric = NAMEOF('measure_tbl'[carInv_measure]), carInv,&lt;BR /&gt;metric = NAMEOF('measure_tbl'[toyInv_measure]), toyInv,&lt;BR /&gt;metric = NAMEOF('measure_tbl'[bearInv_measure]), bearInv,&lt;BR /&gt;etc..&lt;BR /&gt;)&lt;BR /&gt;RETURN&lt;BR /&gt;RESULT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;targetKPI =&lt;BR /&gt;VAR metric =&lt;BR /&gt;SELECTEDVALUE ( 'targets'[targets_fields] )&lt;BR /&gt;VAR carInv = [carInv_measure_target]&lt;BR /&gt;VAR toyInv = [toyInv_measure_target]&lt;BR /&gt;VAR bearInv = [bearInv_measure_target]&lt;BR /&gt;etc..&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;VAR RESULT =&lt;BR /&gt;SWITCH (&lt;BR /&gt;TRUE (),&lt;BR /&gt;metric = NAMEOF('measure_tbl'[carInv_measure_target]), carInv,&lt;BR /&gt;metric = NAMEOF('measure_tbl'[toyInv_measure_target]), toyInv,&lt;BR /&gt;metric = NAMEOF('measure_tbl'[bearInv_measure_target]), bearInv,&lt;BR /&gt;etc..&lt;BR /&gt;)&lt;BR /&gt;RETURN&lt;BR /&gt;RESULT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;targetPct = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt;&lt;SPAN&gt; KpiActual = [averageKPI]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt;&lt;SPAN&gt; KpiTarget = [targetKPI]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt;&lt;SPAN&gt; Result =&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;DIVIDE&lt;/SPAN&gt;&lt;SPAN&gt; ( KpiActual - KpiTarget, KpiTarget )&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;"("&lt;/SPAN&gt;&lt;SPAN&gt; &amp;amp; &lt;/SPAN&gt;&lt;SPAN&gt;FORMAT&lt;/SPAN&gt;&lt;SPAN&gt;(Result,&lt;/SPAN&gt;&lt;SPAN&gt;"0.00%"&lt;/SPAN&gt;&lt;SPAN&gt;) &amp;amp; &lt;/SPAN&gt;&lt;SPAN&gt;")"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 04 Sep 2024 20:49:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Query/m-p/4134116#M164208</guid>
      <dc:creator>cchilton</dc:creator>
      <dc:date>2024-09-04T20:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize DAX Query</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Query/m-p/4134140#M164209</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="441219" data-lia-user-login="cchilton" class="lia-mention lia-mention-user"&gt;cchilton&lt;/a&gt;&amp;nbsp;- You need to un-pivot the table that has your data in them so that you end up with 1 column each for the Actual and Targets and an additional column that defines whether those figures are CarInv, ToyInv or BearInv etc (call this measure name).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you only need to create one DAX measure which will be&amp;nbsp;&lt;SPAN&gt;DIVIDE&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;( KpiActual - KpiTarget, KpiTarget ). A slicer for the measure name column will filter out all the rows &amp;amp; values that are not needed for the calculation.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I wouldnt try to solve this with DAX it's a modelling issue. Here is an article I wrote on un-pivoting data:&amp;nbsp;&lt;A href="https://triangle.im/power-bi-mistake-5-why-pivoted-data-leads-to-power-bi-pain/" target="_blank" rel="noopener"&gt;https://triangle.im/power-bi-mistake-5-why-pivoted-data-leads-to-power-bi-pain/&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If this helps, please mark it as a solution for others - it helps with visibility.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 21:26:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Query/m-p/4134140#M164209</guid>
      <dc:creator>mark_endicott</dc:creator>
      <dc:date>2024-09-04T21:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize DAX Query</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Query/m-p/4134141#M164210</link>
      <description>&lt;P&gt;Hello, I am using field parameters for&amp;nbsp;&lt;SPAN&gt;SELECTEDVALUE ( 'values'[value_fields] ) and&amp;nbsp;SELECTEDVALUE ( 'targets'[targets_fields] ). That's why I can't seem to find a way around using these long painful SWITCH statements. I tried using calculation groups too but I can't get that to work either.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 21:31:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Query/m-p/4134141#M164210</guid>
      <dc:creator>cchilton</dc:creator>
      <dc:date>2024-09-04T21:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize DAX Query</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Query/m-p/4134158#M164211</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="441219" data-lia-user-login="cchilton" class="lia-mention lia-mention-user"&gt;cchilton&lt;/a&gt;&amp;nbsp;- Yep, if you have 60 different variables a field parameter will be a really bad idea. It will take a long time to code up in DAX.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A calculation group could be less time to code up, but it could also be equal - it largely depends how you have set your tables up and named the measures.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I honestly think you'd be better off returning to how your model has been set up and fixing things there. If your model had a column to filter the Actual and Total values, you would not need 60 different measures for Actual and Target. You would need one for each column, also your problems with slow loading of visuals will disappear.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 21:58:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Query/m-p/4134158#M164211</guid>
      <dc:creator>mark_endicott</dc:creator>
      <dc:date>2024-09-04T21:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize DAX Query</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Query/m-p/4138269#M164386</link>
      <description>&lt;P&gt;Below is how my model is set up in Power BI.&amp;nbsp; I am using Direct Query mode. I have other virtual tables connected to different power query parameters for filtering purposes. I have one table that holds all of my calculations/measures as well. I do not understand how I can change this to make it more effective?&amp;nbsp; Should I create a table back at the data source that holds all of my calculations rather than doing them all in DAX? I have thought about doing this for awhile but I wasn't sure if it was the right way to go. Thank you for any help you are able to provide!!! (the one table called "calculation table" is just one calculation that I had to do at the data source, it would not work with DAX in direct query mode)&amp;nbsp;&lt;BR /&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2024 19:16:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Query/m-p/4138269#M164386</guid>
      <dc:creator>cchilton</dc:creator>
      <dc:date>2024-09-06T19:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize DAX Query</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Query/m-p/4140282#M164521</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="441219" data-lia-user-login="cchilton" class="lia-mention lia-mention-user"&gt;cchilton&lt;/a&gt;&amp;nbsp;- I'm assuming you need to write up to 60 different measures because of all the separate "Target" columns I see in the "company_targets" table. If this is true, this is the table that needs to be&amp;nbsp;&lt;SPAN&gt;un-pivoted, although as you're using DQ this should be done within the database rather than in Power BI.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I can't provide any more guidance until I see the DAX you are using for the [carInv_measure],&amp;nbsp;[toyInv_measure] and&amp;nbsp;[bearInv_measure] measures - this will give me an idea if you can do something similar with the table that these measures work off of.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As an aside, I see you have 3 tables which could be interpreted as containing dates, "date_dimension", "Quarters" and "GroupedDates" in an ideal world and to optimise your model, these should be rolled into one table. Furthermore, this model is Snowflaked, with lots of dimensions being connected to other dimensions and sometimes with 1-to-1 relationships. Again to optimise this model, and to fit with Power BI best practices I would advise you to unite this tables at source to make this a more traditional Star Schema, it will make your DAX mush easier as well as allowing for more optimal queries being sent to your datasource.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2024 08:49:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Query/m-p/4140282#M164521</guid>
      <dc:creator>mark_endicott</dc:creator>
      <dc:date>2024-09-09T08:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize DAX Query</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Query/m-p/4142357#M164626</link>
      <description>&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;Thanks for the reply from mark_endicott&amp;nbsp;, please allow me to provide another insight:&lt;/P&gt;
&lt;P&gt;Hi,&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="441219" data-lia-user-login="cchilton" class="lia-mention lia-mention-user"&gt;cchilton&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Regarding the issue you raised, my solution is as follows:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1.&lt;/SPAN&gt;&lt;SPAN&gt;First, you can use aggregation tables: create one or more aggregation tables that contain pre-computed summary data. This reduces the amount of computation when querying.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P lang="zh-CN"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Here's the documentation:&lt;BR /&gt;&lt;/SPAN&gt;&lt;A href="https://radacad.com/aggregation-to-speed-up-the-performance-of-a-power-bi-report-even-if-all-imported" target="_blank" rel="nofollow noopener noreferrer"&gt;&lt;SPAN&gt;Aggregation to speed up the performance of a Power BI report even if all IMPORTED - RADACAD&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2.&lt;/SPAN&gt;&lt;SPAN&gt;Second, use automatic aggregations: Power BI provides automatic aggregation capabilities that automatically create and maintain aggregation tables based on query patterns to optimize performance.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P lang="zh-CN"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P lang="zh-CN"&gt;Here's a screenshot of the documentation:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/power-bi/enterprise/aggregations-auto" target="_blank" rel="nofollow noopener noreferrer"&gt;&lt;SPAN&gt;Automatic aggregations overview - Power BI | Microsoft Learn&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3.&lt;/SPAN&gt;&lt;SPAN&gt;Finally, there are official links related to performance optimization, I hope it will be helpful to you:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/power-bi/guidance/power-bi-optimization" target="_blank" rel="nofollow noopener noreferrer"&gt;&lt;SPAN&gt;Optimization guide for Power BI - Power BI | Microsoft Learn&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;A href="https://learn.microsoft.com/en-us/power-bi/guidance/report-performance-troubleshoot" target="_blank" rel="nofollow noopener noreferrer"&gt;&lt;SPAN&gt;Troubleshoot report performance in Power BI - Power BI | Microsoft Learn&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Of course, if you have any new ideas, you are welcome to contact us.&lt;BR /&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Leroy Lu&lt;/P&gt;
&lt;P&gt;If this post&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;helps&lt;/SPAN&gt;, then please consider Accept it&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;as the solution&amp;nbsp;&lt;/SPAN&gt;to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Sep 2024 08:42:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Optimize-DAX-Query/m-p/4142357#M164626</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-09-10T08:42:31Z</dc:date>
    </item>
  </channel>
</rss>

