<?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: DAX Polynomial Regression Calculation Issue in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/2018932#M44939</link>
    <description>&lt;P&gt;This is what I get when I make that change:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Good match except for x = 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that you need to make the same change for each of [a], [b], [c] or else change your final line of [values (poly fit)] to&amp;nbsp;&lt;STRONG&gt;a*[zSequence1ToN]^2+b*[zSequence1ToN]+c&lt;/STRONG&gt; (use the variables you've already computed instead of referencing other measures).&lt;/P&gt;</description>
    <pubDate>Mon, 16 Aug 2021 14:39:08 GMT</pubDate>
    <dc:creator>AlexisOlson</dc:creator>
    <dc:date>2021-08-16T14:39:08Z</dc:date>
    <item>
      <title>DAX Polynomial Regression Calculation Issue</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/2016095#M44856</link>
      <description>&lt;P&gt;I am attempting to implement a 2nd order polynomial regression to fit some data. It appears that I can calculate the coefficients for the regression equation correctly, but I just cannot figure out how to correctly return the correct result of the equation to use in a table/chart. Starting from &lt;A href="https://xxlbi.com/blog/simple-linear-regression-in-dax/" target="_self"&gt;this solution&lt;/A&gt;, I ended up with the following measure:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;values (poly fit) = 
// Reference: https://www.thedatascientists.com/polynomial-regression/
//            https://metric.ma.ic.ac.uk/metric_public/matrices/inverses/inverses2.html
// Because our Xs (dates) and Ys (measures) are in different tables, we have to temporarily create a new table (Known) with both of those values so we can perform SUMX operations easily.
// To get the same polynomial fit as excel, the x values in the calculation are masked over with 1 thru n. Thus x-values in the calc are n+1-min(n)
var countItems = COUNTX(VALUES(Table1[date]),Table1[date])
var Known = 
    SELECTCOLUMNS (
        ALLSELECTED(Table1[date]),
        "KnownX", [zSequence1ToN],
        "KnownY", CALCULATE(SUMX(Table1,[values]))
    )
var sumOfXs = SUMX(Known, [KnownX])
var sumOfYs = SUMX(Known, [KnownY])
var sumOfX2 = SUMX(Known, [KnownX] ^ 2)
var sumOfX3 = SUMX(Known, [KnownX] ^ 3)
var sumOfX4 = SUMX(Known, [KnownX] ^ 4)
var sumOfXY = SUMX(Known, [KnownX] * [KnownY])
var sumOfX2Y = SUMX(Known, [KnownX] ^ 2 * [KnownY])
var determinant = countItems*((sumOfX2*sumOfX4)-(sumOfX3*sumOfX3))-sumOfXs*((sumOfXs*sumOfX4)-(sumOfX2*sumOfX3))+sumOfX2*((sumOfXs*sumOfX3)-(sumOfX2*sumOfX2))

//Calculate the inverse matrix (combining a few steps together)
var M11 = ((sumOfX2*sumOfX4)-(sumOfX3*sumOfX3))/determinant
var M12 = -((sumOfXs*sumOfX4)-(sumOfX3*sumOfX2))/determinant
var M13 = -((sumOfX2*sumOfX2)-(sumOfXs*sumOfX3))/determinant //there was an error on this line i had to add a negative to fix. no idea why. EVERY other var evaluates correctly.
var M21 = -((sumOfXs*sumOfX4)-(sumOfX2*sumOfX3))/determinant
var M22 = ((countItems*sumOfX4)-(sumOfX2*sumOfX2))/determinant
var M23 = -((countItems*sumOfX3)-(sumOfXs*sumOfX2))/determinant
var M31 = ((sumOfXs*sumOfX3)-(sumOfX2*sumOfX2))/determinant
var M32 = -((countItems*sumOfX3)-(sumOfX2*sumOfXs))/determinant
var M33 = ((countItems*sumOfX2)-(sumOfXs*sumOfXs))/determinant

//Assuming equation of: a*x^2 + b*x + c
var c = M11*sumOfYs+M12*sumOfXY+M13*sumOfX2Y
var b = M21*sumOfYs+M22*sumOfXY+M23*sumOfX2Y
var a = M31*sumOfYs+M32*sumOfXY+M33*sumOfX2Y

RETURN
    // SUMX(
    //     DISTINCT(Table1[date]),
    //     a * [zSequence1ToN] ^ 2 + b * [zSequence1ToN] + c
    // )
    [a]*[zSequence1ToN]^2+[b]*[zSequence1ToN]+[c]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where [zSequence1ToN] is a RANKX of the date values&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;zSequence1ToN = RANKX(ALLSELECTED(Table1[date]),CALCULATE(SUM(Table1[date])),,ASC)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My issue is I cannot figure out how to correctly calculate this for each row in the table. The screenshot below is what I am getting (compared to what I should be getting - at least according to excel.&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;I suspect my issue may be where I am returning the values, but at this point I am out of ideas and need advice. I have attached a sample pbix file and the excel file I was using for validation. What am I doing wrong?&lt;/P&gt;&lt;P&gt;&lt;A href="https://1drv.ms/u/s!Ah3VDq5HnODQgcArelYadi0cXQQZzA?e=8YdvQK" target="_self"&gt;https://1drv.ms/u/s!Ah3VDq5HnODQgcArelYadi0cXQQZzA?e=8YdvQK&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 20:52:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/2016095#M44856</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-08-13T20:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Polynomial Regression Calculation Issue</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/2016120#M44857</link>
      <description>&lt;P&gt;I think the main problem here is this: &lt;STRONG&gt;COUNTX(VALUES(Table1[date]),Table1[date])&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;This is evaluated within the local filter context and returns 1 for each row corresponding to a single date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this instead:&amp;nbsp;&lt;STRONG&gt;COUNTROWS ( ALLSELECTED ( Table1[date] ) )&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 21:39:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/2016120#M44857</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2021-08-13T21:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Polynomial Regression Calculation Issue</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/2018814#M44929</link>
      <description>&lt;P&gt;Thank you for your input, however that did not seem to have any effect. Would that have an effect on the final return result if that var only returns a single number of the count?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 14:04:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/2018814#M44929</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-08-16T14:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Polynomial Regression Calculation Issue</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/2018932#M44939</link>
      <description>&lt;P&gt;This is what I get when I make that change:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Good match except for x = 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that you need to make the same change for each of [a], [b], [c] or else change your final line of [values (poly fit)] to&amp;nbsp;&lt;STRONG&gt;a*[zSequence1ToN]^2+b*[zSequence1ToN]+c&lt;/STRONG&gt; (use the variables you've already computed instead of referencing other measures).&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 14:39:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/2018932#M44939</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2021-08-16T14:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Polynomial Regression Calculation Issue</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/2018985#M44941</link>
      <description>&lt;P&gt;That's a facepalm moment. I was indeed using the measures instead of the variables. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the moral of the story is that local filter context is passed down through dependent variables too. That is something I would not have considered.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 14:59:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/2018985#M44941</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-08-16T14:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Polynomial Regression Calculation Issue</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/2018989#M44942</link>
      <description>&lt;P&gt;Yes. Each VAR is calculated within the local filter context.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 15:01:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/2018989#M44942</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2021-08-16T15:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Polynomial Regression Calculation Issue</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/2887978#M93676</link>
      <description>&lt;P&gt;Hi, PLEASE HELP!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm prototyping a similar calculation in excel for a 4th order polynomial with a 5x5 matrix, but I cannot seem to generate the same result as LINEST() in excel, see attached....&lt;/P&gt;&lt;P&gt;&lt;A title="Polynomial regression manual calculation..." href="https://1drv.ms/x/s!AsId0OAmsuzuhOEh7CR03iyUCLAbng?e=fiK5ay" target="_self"&gt;https://1drv.ms/x/s!AsId0OAmsuzuhOEh7CR03iyUCLAbng?e=fiK5ay&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've used the Chio method of expansion to compute the determinant...&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.youtube.com/watch?v=_JetUVpvFAU" target="_self"&gt;https://www.youtube.com/watch?v=_JetUVpvFAU&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've then computed matrix of minors and matrix of cofactors to work out the inverse of the original 5x5 matrix, as instructed here...&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.mathsisfun.com/algebra/matrix-inverse-minors-cofactors-adjugate.html" target="_self"&gt;https://www.mathsisfun.com/algebra/matrix-inverse-minors-cofactors-adjugate.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2022 01:46:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/2887978#M93676</guid>
      <dc:creator>kopite</dc:creator>
      <dc:date>2022-11-07T01:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Polynomial Regression Calculation Issue</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/2888230#M93685</link>
      <description>&lt;P&gt;Found a solution for a 5x5 matrix using Chio method of expansion and Cramer's Rule, parsing the solution vector into a series of matrices, to calculate determinants divided by the original determinant to solve for the polynomial regression coefficients...&lt;/P&gt;&lt;P&gt;&lt;A href="https://1drv.ms/x/s!AsId0OAmsuzuhOEh7CR03iyUCLAbng?e=WKULj9" target="_self"&gt;https://1drv.ms/x/s!AsId0OAmsuzuhOEh7CR03iyUCLAbng?e=WKULj9&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2022 05:11:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/2888230#M93685</guid>
      <dc:creator>kopite833</dc:creator>
      <dc:date>2022-11-07T05:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Polynomial Regression Calculation Issue</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/3667079#M142175</link>
      <description>&lt;P&gt;I have a matrix with 2 columns from which i want to run a polynomial regression to the fourth degree to fit a line on data.&amp;nbsp; The fourth degree is to smooth the data basically looking at daily data with a smoothing effect over a four week period.&amp;nbsp; I can't seem to convert the equations of the DAX code above to give me the results of a fourth degree and struggling to convert your excel spreadsheet to those equations.&amp;nbsp; Any help would be greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2024 23:29:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Polynomial-Regression-Calculation-Issue/m-p/3667079#M142175</guid>
      <dc:creator>ToddFEagle2023</dc:creator>
      <dc:date>2024-01-29T23:29:04Z</dc:date>
    </item>
  </channel>
</rss>

