<?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: Avoid Repeating Virtual Table in Every Measure in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Avoid-Repeating-Virtual-Table-in-Every-Measure/m-p/3276342#M121544</link>
    <description>&lt;P&gt;I don't think there's a way to avoid having the code in each measure, but you might get a performance boost by using ADDCOLUMNS to add the calculated columns rather than SUMMARIZE.&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;ADDCOLUMNS (
    SUMMARIZE (
        FILTER (
            ALL ( Data ),
            Data[Date] &amp;gt;= MinDate
                &amp;amp;&amp;amp; Data[Date] &amp;lt;= MaxDate
                &amp;amp;&amp;amp; Data[Ticker] = Ticker
        ),
        Data[Date]
    ),
    "L", CALCULATE ( MIN ( Data[Low] ) ),
    "_RUN", [_Run]
)&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 09 Jun 2023 10:01:15 GMT</pubDate>
    <dc:creator>johnt75</dc:creator>
    <dc:date>2023-06-09T10:01:15Z</dc:date>
    <item>
      <title>Avoid Repeating Virtual Table in Every Measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Avoid-Repeating-Virtual-Table-in-Every-Measure/m-p/3276069#M121531</link>
      <description>&lt;P&gt;I have a dynamic chart that changes its appeareance based on selection in a table.&amp;nbsp; In the example below the orange curve line is the generated result.&amp;nbsp; I used a Virtual Table (via Summarize) to speed up the calculation.&amp;nbsp; I have a lot of measures using this approach, and I am afraid repeating this&amp;nbsp;Virtual Table in every measure will cause slow performance (right now it takes up to 3-5 secs for chart to load).&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I was wondering if I can have this Virtual Table centralized (write it once) and refer to it to speed up performance.&amp;nbsp; I tried adding the Virtual Table as a new Table rather than inside the measure, but this approach doesn't work because Tables are not updated upon query selection (updates at data load).&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Alternatively, are there other approaches or best practices I should follow to improve performance?&lt;BR /&gt;&lt;BR /&gt;Here is the DAX code:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Cv.RoundV_L = 
VAR MinDate = CALCULATE( MIN(Data[Start]), ALLSELECTED(Data) )
VAR MaxDate = CALCULATE( MIN(Data[End]), ALLSELECTED(Data) )
VAR Ticker = [_Ticker]

//Virtual table to make calculation faster --- This is Key ***
VAR _Mini = SUMMARIZE( FILTER( ALL(Data), Data[Date] &amp;gt;= MinDate &amp;amp;&amp;amp; Data[Date] &amp;lt;= MaxDate &amp;amp;&amp;amp; Data[Ticker] = Ticker ), Data[Date], "L", MIN(Data[Low]), "_RUN", [_Run]  )

//Given a vertex(h,k), find the quadratic equation of a parabola 
// Y = a(X-h)^2 + k or Y = aX^2 + bX + c
// Solve for a, which is a = (Y-k) / (X-h)^2
// Since the vertex is some time to the left or right, thus below combines 2 half curves to make a nice curve 
VAR Ymin = SUMX( FILTER( _Mini, [_RUN] = 0 ), [L] )     //find the Px_L of the starting point at MinDate or RunCount = 0
VAR Vk = MINX( _Mini,[L])                               //Find the lowest point Px_L
VAR Vh_L = SUMX( FILTER( _Mini, [L] = Vk ), [_RUN] )    //Find the RunCount X of the lowest point 

//Left side of vertex -- Curve A
VAR aLeft = DIVIDE( (Ymin - Vk), (0-Vh_L)^2 )
VAR LCurve = SUMX( FILTER( _Mini, Data[Date] = MIN('Date'[Date]) ), aLeft * ([_RUN] - Vh_L)^2 + Vk ) //Date=Min(Date) to show each date (avoid aggregation) 

//Right side of vertex -- Curve B
VAR Xmax = MAXX( _Mini, [_RUN] )
VAR Ymax = SUMX( FILTER( _Mini, [_RUN] = Xmax ), [L] )
VAR Vh_R = Xmax - Vh_L
VAR Xoffset = Vh_L - Vh_R                                //Curve calc starts at Run = 0, thus shift curve to right
VAR aRight = DIVIDE( (Ymax - Vk), (0-Vh_R)^2 )
VAR RCurve = SUMX( FILTER( _Mini, Data[Date] = MIN('Date'[Date]) ), aRight * ([_RUN]-Xoffset - Vh_R)^2 + Vk )

//Putting it together
VAR RunCnt = SUMX( FILTER( _Mini, Data[Date] = MIN('Date'[Date]) ), [_RUN] )
RETURN
    IF( RunCnt &amp;lt;= Vh_L, LCurve, RCurve )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 07:36:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Avoid-Repeating-Virtual-Table-in-Every-Measure/m-p/3276069#M121531</guid>
      <dc:creator>alchen00</dc:creator>
      <dc:date>2023-06-09T07:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid Repeating Virtual Table in Every Measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Avoid-Repeating-Virtual-Table-in-Every-Measure/m-p/3276342#M121544</link>
      <description>&lt;P&gt;I don't think there's a way to avoid having the code in each measure, but you might get a performance boost by using ADDCOLUMNS to add the calculated columns rather than SUMMARIZE.&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;ADDCOLUMNS (
    SUMMARIZE (
        FILTER (
            ALL ( Data ),
            Data[Date] &amp;gt;= MinDate
                &amp;amp;&amp;amp; Data[Date] &amp;lt;= MaxDate
                &amp;amp;&amp;amp; Data[Ticker] = Ticker
        ),
        Data[Date]
    ),
    "L", CALCULATE ( MIN ( Data[Low] ) ),
    "_RUN", [_Run]
)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 09 Jun 2023 10:01:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Avoid-Repeating-Virtual-Table-in-Every-Measure/m-p/3276342#M121544</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2023-06-09T10:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid Repeating Virtual Table in Every Measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Avoid-Repeating-Virtual-Table-in-Every-Measure/m-p/3276543#M121549</link>
      <description>&lt;P&gt;Thank you for your wisdom.&amp;nbsp; I implemented the solution and got a 40% time reduction (360ms vs 213ms).&amp;nbsp; On a combined basis hope it make it more efficient.&amp;nbsp; Thank you again.&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 12:15:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Avoid-Repeating-Virtual-Table-in-Every-Measure/m-p/3276543#M121549</guid>
      <dc:creator>alchen00</dc:creator>
      <dc:date>2023-06-09T12:15:44Z</dc:date>
    </item>
  </channel>
</rss>

