title: Multiple Linear Regression in Power BI
body: <p>Suppose I have a set of returns and I want to compute its beta values versus different market indices. Let's use the following set of data in a table named <code>Returns</code> for the sake of having a concrete example:</p>
  
  <pre><code>  Date       Equity  Duration  Credit  Manager
  -----------------------------------------------
  01/31/2017   2.907%   0.226%   1.240%   1.78%
  02/28/2017   2.513%   0.493%   1.120%   3.88%
  03/31/2017   1.346%  -0.046%  -0.250%   0.13%
  04/30/2017   1.612%   0.695%   0.620%   1.04%
  05/31/2017   2.209%   0.653%   0.480%   1.40%
  06/30/2017   0.796%  -0.162%   0.350%   0.63%
  07/31/2017   2.733%   0.167%   0.830%   2.06%
  08/31/2017   0.401%   1.083%  -0.670%   0.29%
  09/30/2017   1.880%  -0.857%   1.430%   2.04%
  10/31/2017   2.151%  -0.121%   0.510%   2.33%
  11/30/2017   2.020%  -0.137%  -0.020%   3.06%
  12/31/2017   1.454%   0.309%   0.230%   1.28%
  </code></pre>
  
  <p>Now in Excel, I can just use the <code>LINEST</code> function to get the beta values:</p>
  
  <pre><code>= LINEST(Returns[Manager], Returns[[Equity]:[Credit]], TRUE, TRUE)
  </code></pre>
  
  <p>It spits out an array that looks like this:</p>
  
  <pre><code>0.077250253 -0.184974002  0.961578127 -0.001063971
  0.707796954  0.60202895   0.540811546  0.008257129
  0.50202386   0.009166729  #N/A         #N/A
  2.688342242  8            #N/A         #N/A
  0.000677695  0.000672231  #N/A         #N/A
  </code></pre>
  
  <p>The betas are in the top row and using them gives me the following linear estimate:</p>
  
  <pre><code>Manager = 0.962 * Equity - 0.185 * Duration + 0.077 * Credit - 0.001
  </code></pre>
  
  <p>The question is how can I get these values in Power BI using DAX (preferably without having to write a custom R script)?</p>
  
  <hr>
  
  <p>For <a href="https://en.wikipedia.org/wiki/Simple_linear_regression" rel="noreferrer">simple linear regression</a> against one column, I can go back to the mathematical definition and write a least squares implementation similar to the one given in <a href="https://community.powerbi.com/t5/Desktop/Simple-Linear-Regression-with-DAX/td-p/9272" rel="noreferrer">this post</a>.</p>
  
  <p>However, when more columns become involved (I need to be able to do up to 12 columns, but not always the same number), this gets messy really quickly and I'm hoping there's a better way.</p>