Use Custom DAX to create a Linear Regression Trendline with a Dynamic Date Hierarchy in Power BI

Published Jul 29 2021 07:03 AM 2,528 Views
Microsoft

Custom Linear Regression DAX expressions give you insights into all components of the Y = MX + B equation.Custom Linear Regression DAX expressions give you insights into all components of the Y = MX + B equation.

 

Recently I was asked to provide an example of a custom Linear Regression Trendline in Power BI that can dynamically re-calculate for both different levels of a Date hierarchy along with different filter selections. After designing and creating the example, I thought it would be useful to share with the Community. Linear trendlines can be useful for trendspotting, forecasting, and pattern identification in data. In this article (and related video tutorial) I'll cover the following:

  1. Add a Linear Regression Trendline to a Dataset and Report using custom DAX
  2. Visualize and interpret the DAX calculations
  3. Provide a link to a sample PBIX file with a copy of the solution
  4. (Video) Discuss how to extend the Linear Regression Trendline calculations to uncover trends within the data and visualize patterns at scale

The approach used in this example could be applied to any data on a date axis, for any industry. In Healthcare (this is a Healthcare Blog) some examples might include Average Length of Stay, Complications, Falls, Performance Metric Rates, Supply Chain Metrics, and more. These dynamic calculations can be used to simply visualize trends, or to bubble up specific sub-categories of data that are sharply trending up or down over time. For a metric such as Average Length of Stay, users could browse the Power BI report to compare trends over time by Department, DRG, Floor, Primary Diagnoses, Location, Day of Week, etc and find areas in need of attention. 

 

Before reading any further, if you are looking for a simple trendline on a chart then there is an out-of-the-box option that only takes a few clicks (click here). If you'd like to do advanced analytics, have access to the underlying calculations with a custom version, and compare different slices of the data interactively to bubble up opportunities then keep reading.

 

For the purpose of this example, a linear regression trendline will be calculated using hierarchical values on a Date axis. The aggregated values for each member of the Date axis will be used to calculate the equation of a linear regression trendline such that Y = MX + B:

  • Y is the y axis value of the trendline at each Date interval.
  • M is the slope of the trendline.
  • X is the order of the value on the x axis.
  • B is the point where the trendline starts on the y axis.

The Linear Regression Trendline will works for Weeks, Months, Quarters, and Years depending on the level you choose to view in a report. Adjusting the level of Date aggregation can be helpful when your data has both smaller sample sizes that need to be aggregated over broader periods of time, or robust sample sizes that need to be analyzed daily or weekly.

 

Prerequisites

  1. This demo can be built in either Power BI Desktop, Azure Analysis Services, SQL Server Analysis Services, or Excel PowerPivot Tabular Models.
  2. You'll need a good Date Table as part of your Model. I provide free scripts for Date tables at this link: https://github.com/gregbeaumont/PowerPopHealth/tree/main/Date%20%26%20Time%20Scripts 
  3. You'll also need a Fact table with calculations having a Date key. The example I've used for the demo can be replicated from this link (real CDC Population Weighted UV Irradiance data): https://github.com/gregbeaumont/PowerPopHealth/tree/main/CDC 
  4. For this demo, I added a new column to the Date Table for the [Week Index]. This column is only necessary if you want to have trendlines at the weekly level. The [Week Index] starts at 1 for the earliest week in your Date table, and increases each week by one over the course of all weeks in the Date table. Date aggregations other than Week (Month, Quarter, Year) support Time Intelligence DAX expressions and such an Index is not needed.

A link to download my full demo PBIX file for this article is herehttps://github.com/gregbeaumont/PowerPopHealth/tree/main/Demos 

 

A video detailing how the regression will work and can provide value is embedded after the DAX expressions, or you can view it here.

 

Linear Regression Trendline DAX Expressions

 

This example will build a linear regression trendline for a calculated value over the course of Years, Quarters, Months or Weeks that are plotted on the x axis. I used an Average of i380 ([i380 Avg] is a measurement of radiation taken daily for the CDC in every US County) for the calculated value. You can replace [i380 Avg] with your own calculation if you add your own fact table to the solution.

 

I chose the CDC data for the demo because it was robust, real, and I had it ready to go for another project. The purpose of this demo is not to extract insights from the sample data, but to prove out the method for calculating a linear regression using DAX. An astute analyst will probably notice that a nonlinear regression would work better with this CDC data since solar radiation levels are seasonal.

 

I want to add a few quick notes about the DAX measures in this solution. The code snippets below look complicated, but they consist of a few patterns that repeat. Also, the DAX measures perform well on the sample data containing 12.3 million rows of daily measurements for every County in the USA. There might be some additional opportunities to improve the query performance using variables and calculation groups, any suggestions are welcome in the comments.

 

Create each of these DAX Measures in the following order:

  1. Run Count (X) = //* A calculation to count the number of measurements that are included on the axis
    var MinDate = CALCULATE(MIN('CDC Pop Rated UV Irradiance'[Date]),ALLSELECTED('Date')) //* A variable to pre-calculate the earliest Date
    RETURN
    SWITCH(TRUE(),
    ISFILTERED('Date'[Week Year]),CALCULATE(DISTINCTCOUNT('Date'[Week Year]),FILTER(ALL('Date'[Date]),[Date] <= MAX('CDC Pop Rated UV Irradiance'[Date]) && [Date] >= MinDate)), //* Calculate the number of weeks leading up to and including the current week.
    ISFILTERED('Date'[Month Year]),CALCULATE(DISTINCTCOUNT('Date'[Month Year]),FILTER(ALL('Date'[Date]),[Date] <= MAX('CDC Pop Rated UV Irradiance'[Date]) && [Date] >= MinDate)), //* Calculate the number of months leading up to and including the current month.
    ISFILTERED('Date'[Quarter Year]),CALCULATE(DISTINCTCOUNT('Date'[Quarter Year]),FILTER(ALL('Date'[Date]),[Date] <= MAX('CDC Pop Rated UV Irradiance'[Date]) && [Date] >= MinDate)), //* Calculate the number of quarters leading up to and including the current quarter.
    ISFILTERED('Date'[Year]),CALCULATE(DISTINCTCOUNT('Date'[Year]),FILTER(ALL('Date'[Date]),[Date] <= MAX('CDC Pop Rated UV Irradiance'[Date]) && [Date] >= MinDate)), //* Calculate the number of years leading up to and including the current year.
    BLANK() //* Return a blank if other columns are used on the axis. )
  2. i380 Avg = AVERAGE([i380]) //* An average of the values in a column on the Fact table. This could also be a SUM or some other sort of calculated measure that you are putting on an axis.
  3. i380 Avg Prev = //* A calculation of the previous calculation on the axis. 
    var WeekIndexPrev = MAX('Date'[Week Index]) - 1 //* A variable for the Index of the previous week. Time Intelligence doesn't work at the week level, so this is only needed if you want to have weekly values on the axis.
    RETURN
    SWITCH(TRUE(),
    [Run Count (X)] < 1,BLANK(), //* Don't show any values if either 1) the current member on the axis is the first one, or 2) the current member is not on the axis of the visual.
    ISFILTERED('Date'[Week Year]),CALCULATE([i380 Avg],FILTER(ALL('Date'),'Date'[Week Index] = WeekIndexPrev)), //* Calculate the i380 Avg for the previous week.
    ISFILTERED('Date'[Month Year]),CALCULATE([i380 Avg],PREVIOUSMONTH('Date'[Date])), //* Calculate the i380 Avg for the previous month.
    ISFILTERED('Date'[Quarter Year]),CALCULATE([i380 Avg],PREVIOUSQUARTER('Date'[Date])), //* Calculate the i380 Avg for the previous quarter.
    ISFILTERED('Date'[Year]),CALCULATE([i380 Avg],PREVIOUSYEAR('Date'[Date])), //* Calculate the i380 Avg for the previous year.
    BLANK() //* Return a blank if other columns are used on the axis.
    )
  4. Rise = //* Calculate the delta (change) of the calculated measure between the current and previous Months on the axis.
    SWITCH(TRUE(),
    [Run Count (X)] <= 1, BLANK(), //* Don't show any values if either 1) the current member on the axis is the first one, or 2) the current member is not on the axis of the visual.
    [i380 Avg] - [i380 Avg Prev])
  5. Avg Rise (M) = //* Calculate the average rise for the entire series of data. 
    SWITCH(TRUE(),
    [Run Count (X)] < 1,BLANK(), //* Don't show any values if either 1) the current member on the axis is the first one, or 2) the current member is not on the axis of the visual.
    ISFILTERED('Date'[Week Year]),CALCULATE(AVERAGEX(SUMMARIZE('Date','Date'[Week Year]),[Rise]),ALLSELECTED('Date')), //* Calculate the average rise at the week level for all dates that have been selected.
    ISFILTERED('Date'[Month Year]),CALCULATE(AVERAGEX(SUMMARIZE('Date','Date'[Month Year]),[Rise]),ALLSELECTED('Date')), //* Calculate the average rise at the month level for all dates that have been selected.
    ISFILTERED('Date'[Quarter Year]),CALCULATE(AVERAGEX(SUMMARIZE('Date','Date'[Quarter Year]),[Rise]),ALLSELECTED('Date')), //* Calculate the average rise at the quarter level for all dates that have been selected.
    ISFILTERED('Date'[Year]),CALCULATE(AVERAGEX(SUMMARIZE('Date','Date'[Year]),[Rise]),ALLSELECTED('Date')), //* Calculate the average rise at the year level for all years that have been selected.
    BLANK() //* Return a blank if other columns are used on the axis.
    )
  6. Y Intercept (B) = //* Calculating the Y intercept, which is the value of the regression line when it crosses zero on the x axis.
    SWITCH(TRUE(),
    [Run Count (X)] < 1,BLANK(), //* Don't show any values if either 1) the current member on the axis is the first one, or 2) the current member is not on the axis of the visual.
    ISFILTERED('Date'[Week Year]),CALCULATE(AVERAGEX(SUMMARIZE('Date','Date'[Week Year]),([i380 Avg] - ([Avg Rise (M)] * [Run Count (X)]))),ALLSELECTED('Date')), //* Calculate the Y intercept at the week level (the B in Y = MX + B) by 1) calculating the (Rise * Run) and then subtracting it from the i380 average and 2) averaging all of those values.
    ISFILTERED('Date'[Month Year]),CALCULATE(AVERAGEX(SUMMARIZE('Date','Date'[Month Year]),([i380 Avg] - ([Avg Rise (M)] * [Run Count (X)]))),ALLSELECTED('Date')), //* Calculate the Y intercept at the month level (the B in Y = MX + B) by 1) calculating the (Rise * Run) and then subtracting it from the i380 average and 2) averaging all of those values.
    ISFILTERED('Date'[Quarter Year]),CALCULATE(AVERAGEX(SUMMARIZE('Date','Date'[Quarter Year]),([i380 Avg] - ([Avg Rise (M)] * [Run Count (X)]))),ALLSELECTED('Date')), //* Calculate the Y intercept at the quarter level (the B in Y = MX + B) by 1) calculating the (Rise * Run) and then subtracting it from the i380 average and 2) averaging all of those values.
    ISFILTERED('Date'[Year]),CALCULATE(AVERAGEX(SUMMARIZE('Date','Date'[Year]),([i380 Avg] - ([Avg Rise (M)] * [Run Count (X)]))),ALLSELECTED('Date')), //* Calculate the Y intercept at the year level (the B in Y = MX + B) by 1) calculating the (Rise * Run) and then subtracting it from the i380 average and 2) averaging all of those values.
    BLANK() //* Return a blank if other columns are used on the axis.
    )
  7. Regression (Y) = ([Avg Rise (M)] * [Run Count (X)]) + [Y Intercept (B)] //* Complete the (Y = MX + B) equation for your regression! 

 

Here is a diagram detailing how the above seven DAX expressions interact with each other as you stack them together like building blocks: 

Custom DAX Calculations are used as components of other DAX calculations to complete the Equation and make it dynamic for multidimensional queries.Custom DAX Calculations are used as components of other DAX calculations to complete the Equation and make it dynamic for multidimensional queries.

 

Once you've added these custom DAX expressions to your solution you can not only plot a Regression line at multiple levels of a Date Hierarchy, but also bubble up areas of opportunity in your data. In the example below, Counties can be bubbles up that have the most dramatic increase in [Avg Rise (M)] which means that they have the greatest upward trend over time.

Linear Regression Line Slope (M) can be used to Bubble Up Steeply Increasing or Decreasing slices of data.Linear Regression Line Slope (M) can be used to Bubble Up Steeply Increasing or Decreasing slices of data.

 In Healthcare you could bubble up the trends of measures such as Length of Stay, Complication Rates, Fall Rates, Compliance Rates, Discharge by Noon Rates to answer questions such as:

  • Which Specialties are showing the greatest upwards or downwards trends?
  • What Floors of the building are trending?
  • Which DRGs are trending the wrong way? What if we drill into the data and compare the trends of the bad DRGs by Shift or Primary Diagnoses?

Here is a video describing the process and utility of a custom linear regression trendline using DAX in Power BI: 

 

%3CLINGO-SUB%20id%3D%22lingo-sub-2405245%22%20slang%3D%22en-US%22%3EUse%20Custom%20DAX%20to%20create%20a%20Linear%20Regression%20Trendline%20with%20a%20Dynamic%20Date%20Hierarchy%20in%20Power%20BI%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2405245%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22Regression2.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F298712i926F7F5467C5FA5C%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Regression2.png%22%20alt%3D%22Custom%20Linear%20Regression%20DAX%20expressions%20give%20you%20insights%20into%20all%20components%20of%20the%20Y%20%3D%20MX%20%2B%20B%20equation.%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3ECustom%20Linear%20Regression%20DAX%20expressions%20give%20you%20insights%20into%20all%20components%20of%20the%20Y%20%3D%20MX%20%2B%20B%20equation.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ERecently%20I%20was%20asked%20to%20provide%20an%20example%20of%20a%20custom%20Linear%20Regression%20Trendline%20in%20Power%20BI%20that%20can%20dynamically%20re-calculate%20for%20both%20different%20levels%20of%20a%20Date%20hierarchy%20along%20with%20different%20filter%20selections.%20After%20designing%20and%20creating%20the%20example%2C%20I%20thought%20it%20would%20be%20useful%20to%20share%20with%20the%20Community.%20Linear%20trendlines%20can%20be%20useful%20for%20trendspotting%2C%20forecasting%2C%20and%20pattern%20identification%20in%20data.%20In%20this%20article%20(and%20related%20video%20tutorial)%20I'll%20cover%20the%20following%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EAdd%20a%20Linear%20Regression%20Trendline%20to%20a%20Dataset%20and%20Report%20using%20custom%20DAX%3C%2FLI%3E%0A%3CLI%3EVisualize%20and%20interpret%20the%20DAX%20calculations%3C%2FLI%3E%0A%3CLI%3EProvide%20a%20link%20to%20a%20sample%20PBIX%20file%20with%20a%20copy%20of%20the%20solution%3C%2FLI%3E%0A%3CLI%3E(Video)%20Discuss%20how%20to%20extend%20the%20Linear%20Regression%20Trendline%20calculations%20to%20uncover%20trends%20within%20the%20data%20and%20visualize%20patterns%20at%20scale%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EThe%20approach%20used%20in%20this%20example%20could%20be%20applied%20to%20any%20data%20on%20a%20date%20axis%2C%20for%20any%20industry.%20In%20Healthcare%20(this%20%3CEM%3Eis%3C%2FEM%3E%20a%20Healthcare%20Blog)%20some%20examples%20might%20include%20%3CEM%3EAverage%20Length%20of%20Stay%3C%2FEM%3E%2C%20%3CEM%3EComplications%3C%2FEM%3E%2C%20%3CEM%3EFalls%3C%2FEM%3E%2C%20%3CEM%3EPerformance%20Metric%20Rates%3C%2FEM%3E%2C%20%3CEM%3ESupply%20Chain%20Metrics%3C%2FEM%3E%2C%20and%20more.%20These%20dynamic%20calculations%20can%20be%20used%20to%20simply%20visualize%20trends%2C%20or%20to%20bubble%20up%20specific%20sub-categories%20of%20data%20that%20are%20sharply%20trending%20up%20or%20down%20over%20time.%20For%20a%20metric%20such%20as%20%3CEM%3EAverage%20Length%20of%20Stay%3C%2FEM%3E%2C%20users%20could%20browse%20the%20Power%20BI%20report%20to%20compare%20trends%20over%20time%20by%20Department%2C%20DRG%2C%20Floor%2C%20Primary%20Diagnoses%2C%20Location%2C%20Day%20of%20Week%2C%20etc%20and%20find%20areas%20in%20need%20of%20attention.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBefore%20reading%20any%20further%2C%20if%20you%20are%20looking%20for%20a%20simple%20trendline%20on%20a%20chart%20then%20there%20is%20an%20out-of-the-box%20option%20that%20only%20takes%20a%20%3CA%20href%3D%22https%3A%2F%2Fsqlkover.com%2Fwheres-the-trend-line-in-power-bi-desktop%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Efew%20clicks%20(click%20here)%3C%2FA%3E.%20If%20you'd%20like%20to%20do%20advanced%20analytics%2C%20have%20access%20to%20the%20underlying%20calculations%20with%20a%20custom%20version%2C%20and%20compare%20different%20slices%20of%20the%20data%20interactively%20to%20bubble%20up%20opportunities%20then%20keep%20reading.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20the%20purpose%20of%20this%20example%2C%20a%20linear%20regression%20trendline%20will%20be%20calculated%20using%20hierarchical%20values%20on%20a%20Date%20axis.%20The%20aggregated%20values%20for%20each%20member%20of%20the%20Date%20axis%20will%20be%20used%20to%20calculate%20the%20equation%20of%20a%20linear%20regression%20trendline%20such%20that%20%3CA%20href%3D%22https%3A%2F%2Fwww.mathsisfun.com%2Fequation_of_line.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EY%20%3D%20MX%20%2B%20B%3A%3C%2FA%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EY%3C%2FSTRONG%3E%20is%20the%20y%20axis%20value%20of%20the%20trendline%20at%20each%20Date%20interval.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EM%3C%2FSTRONG%3E%20is%20the%20slope%20of%20the%20trendline.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EX%3C%2FSTRONG%3E%20is%20the%20order%20of%20the%20value%20on%20the%20x%20axis.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EB%3C%2FSTRONG%3E%20is%20the%20point%20where%20the%20trendline%20starts%20on%20the%20y%20axis.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EThe%20Linear%20Regression%20Trendline%20will%20works%20for%20Weeks%2C%20Months%2C%20Quarters%2C%20and%20Years%20depending%20on%20the%20level%20you%20choose%20to%20view%20in%20a%20report.%20Adjusting%20the%20level%20of%20Date%20aggregation%20can%20be%20helpful%20when%20your%20data%20has%20both%20smaller%20sample%20sizes%20that%20need%20to%20be%20aggregated%20over%20broader%20periods%20of%20time%2C%20or%20robust%20sample%20sizes%20that%20need%20to%20be%20analyzed%20daily%20or%20weekly.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EPrerequisites%3C%2FSTRONG%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EThis%20demo%20can%20be%20built%20in%20either%20Power%20BI%20Desktop%2C%20Azure%20Analysis%20Services%2C%20SQL%20Server%20Analysis%20Services%2C%20or%20Excel%20PowerPivot%20Tabular%20Models.%3C%2FLI%3E%0A%3CLI%3EYou'll%20need%20a%20good%20Date%20Table%20as%20part%20of%20your%20Model.%20I%20provide%20free%20scripts%20for%20Date%20tables%20at%20this%20link%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fgregbeaumont%2FPowerPopHealth%2Ftree%2Fmain%2FDate%2520%2526%2520Time%2520Scripts%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fgregbeaumont%2FPowerPopHealth%2Ftree%2Fmain%2FDate%2520%2526%2520Time%2520Scripts%3C%2FA%3E%26nbsp%3B%3C%2FLI%3E%0A%3CLI%3EYou'll%20also%20need%20a%20Fact%20table%20with%20calculations%20having%20a%20Date%20key.%20The%20example%20I've%20used%20for%20the%20demo%20can%20be%20replicated%20from%20this%20link%20(real%20CDC%20Population%20Weighted%20UV%20Irradiance%20data)%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fgregbeaumont%2FPowerPopHealth%2Ftree%2Fmain%2FCDC%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fgregbeaumont%2FPowerPopHealth%2Ftree%2Fmain%2FCDC%26nbsp%3B%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EFor%20this%20demo%2C%20I%20added%20a%20new%20column%20to%20the%20Date%20Table%20for%20the%20%5BWeek%20Index%5D.%20This%20column%20is%20only%20necessary%20if%20you%20want%20to%20have%20trendlines%20at%20the%20weekly%20level.%20The%20%5BWeek%20Index%5D%20starts%20at%201%20for%20the%20earliest%20week%20in%20your%20Date%20table%2C%20and%20increases%20each%20week%20by%20one%20over%20the%20course%20of%20all%20weeks%20in%20the%20Date%20table.%20Date%20aggregations%20other%20than%20Week%20(Month%2C%20Quarter%2C%20Year)%20support%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdax%2Ftime-intelligence-functions-dax%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ETime%20Intelligence%20DAX%20expressions%3C%2FA%3E%20and%20such%20an%20Index%20is%20not%20needed.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EA%20link%20to%20download%20my%20full%20demo%20PBIX%20file%20for%20this%20article%20is%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fgregbeaumont%2FPowerPopHealth%2Ftree%2Fmain%2FDemos%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehere%3C%2FA%3E%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fgregbeaumont%2FPowerPopHealth%2Ftree%2Fmain%2FDemos%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fgregbeaumont%2FPowerPopHealth%2Ftree%2Fmain%2FDemos%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EA%20video%20detailing%20how%20the%20regression%20will%20work%20and%20can%20provide%20value%20is%20embedded%20after%20the%20DAX%20expressions%2C%20or%20you%20can%20%3CA%20href%3D%22https%3A%2F%2Fyoutu.be%2FwWSdQ4FItkM%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Eview%20it%20here%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ELinear%20Regression%20Trendline%20DAX%20Expressions%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20example%20will%20build%20a%20linear%20regression%20trendline%20for%20a%20calculated%20value%20over%20the%20course%20of%20Years%2C%20Quarters%2C%20Months%20or%20Weeks%20that%20are%20plotted%20on%20the%20x%20axis.%20I%20used%20an%20Average%20of%20i380%20(%5Bi380%20Avg%5D%20is%20a%20measurement%20of%20radiation%20taken%20daily%20for%20the%20CDC%20in%20every%20US%20County)%20for%20the%20calculated%20value.%20You%20can%20replace%20%5Bi380%20Avg%5D%20with%20your%20own%20calculation%20if%20you%20add%20your%20own%20fact%20table%20to%20the%20solution.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20chose%20the%20CDC%20data%20for%20the%20demo%20because%20it%20was%20robust%2C%20real%2C%20and%20I%20had%20it%20ready%20to%20go%20for%20another%20project.%20The%20purpose%20of%20this%20demo%20is%20not%20to%20extract%20insights%20from%20the%20sample%20data%2C%20but%20to%20prove%20out%20the%20method%20for%20calculating%20a%20linear%20regression%20using%20DAX.%20An%20astute%20analyst%20will%20probably%20notice%20that%20a%20nonlinear%20regression%20would%20work%20better%20with%20this%20CDC%20data%20since%20solar%20radiation%20levels%20are%20seasonal.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20want%20to%20add%20a%20few%20quick%20notes%20about%20the%20DAX%20measures%20in%20this%20solution.%20The%20code%20snippets%20below%20look%20complicated%2C%20but%20they%20consist%20of%20a%20few%20patterns%20that%20repeat.%20Also%2C%20the%20DAX%20measures%20perform%20well%20on%20the%20sample%20data%20containing%2012.3%20million%20rows%20of%20daily%20measurements%20for%20every%20County%20in%20the%20USA.%20There%20might%20be%20some%20additional%20opportunities%20to%20improve%20the%20query%20performance%20using%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpower-bi%2Fguidance%2Fdax-variables%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Evariables%3C%2FA%3E%20and%20%3CA%20href%3D%22https%3A%2F%2Fwww.sqlbi.com%2Fblog%2Fmarco%2F2020%2F07%2F15%2Fcreating-calculation-groups-in-power-bi-desktop%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ecalculation%20groups%3C%2FA%3E%2C%20any%20suggestions%20are%20welcome%20in%20the%20comments.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECreate%20each%20of%20these%20DAX%20Measures%20in%20the%20following%20order%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CPRE%3E%3CSTRONG%3ERun%20Count%20(X)%3C%2FSTRONG%3E%20%3D%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20A%20calculation%20to%20count%20the%20number%20of%20measurements%20that%20are%20included%20on%20the%20axis%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3Evar%3C%2FFONT%3E%20%3CFONT%20color%3D%22%2333CCCC%22%3EMinDate%3C%2FFONT%3E%20%3D%20%3CFONT%20color%3D%22%230000FF%22%3ECALCULATE%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3EMIN%3C%2FFONT%3E('CDC%20Pop%20Rated%20UV%20Irradiance'%5BDate%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3EALLSELECTED%3C%2FFONT%3E('Date'))%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20A%20variable%20to%20pre-calculate%20the%20earliest%20Date%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3ERETURN%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3ESWITCH%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3ETRUE%3CFONT%20color%3D%22%23000000%22%3E()%3C%2FFONT%3E%3C%2FFONT%3E%2C%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EISFILTERED%3C%2FFONT%3E('Date'%5BWeek%20Year%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3ECALCULATE%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3EDISTINCTCOUNT%3C%2FFONT%3E('Date'%5BWeek%20Year%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3EFILTER%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3EALL%3C%2FFONT%3E('Date'%5BDate%5D)%2C%5BDate%5D%20%26lt%3B%3D%20%3CFONT%20color%3D%22%230000FF%22%3EMAX%3C%2FFONT%3E('CDC%20Pop%20Rated%20UV%20Irradiance'%5BDate%5D)%20%26amp%3B%26amp%3B%20%5BDate%5D%20%26gt%3B%3D%20%3CFONT%20color%3D%22%2333CCCC%22%3EMinDate%3C%2FFONT%3E))%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculate%20the%20number%20of%20weeks%20leading%20up%20to%20and%20including%20the%20current%20week.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EISFILTERED%3C%2FFONT%3E('Date'%5BMonth%20Year%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3ECALCULATE%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3EDISTINCTCOUNT%3C%2FFONT%3E('Date'%5BMonth%20Year%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3EFILTER%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3EALL%3C%2FFONT%3E('Date'%5BDate%5D)%2C%5BDate%5D%20%26lt%3B%3D%20%3CFONT%20color%3D%22%230000FF%22%3EMAX%3C%2FFONT%3E('CDC%20Pop%20Rated%20UV%20Irradiance'%5BDate%5D)%20%26amp%3B%26amp%3B%20%5BDate%5D%20%26gt%3B%3D%20%3CFONT%20color%3D%22%2333CCCC%22%3EMinDate%3C%2FFONT%3E))%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculate%20the%20number%20of%20months%20leading%20up%20to%20and%20including%20the%20current%20month.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EISFILTERED%3C%2FFONT%3E('Date'%5BQuarter%20Year%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3ECALCULATE%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3EDISTINCTCOUNT%3C%2FFONT%3E('Date'%5BQuarter%20Year%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3EFILTER%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3EALL%3C%2FFONT%3E('Date'%5BDate%5D)%2C%5BDate%5D%20%26lt%3B%3D%20%3CFONT%20color%3D%22%230000FF%22%3EMAX%3C%2FFONT%3E('CDC%20Pop%20Rated%20UV%20Irradiance'%5BDate%5D)%20%26amp%3B%26amp%3B%20%5BDate%5D%20%26gt%3B%3D%20%3CFONT%20color%3D%22%2333CCCC%22%3EMinDate%3C%2FFONT%3E))%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculate%20the%20number%20of%20quarters%20leading%20up%20to%20and%20including%20the%20current%20quarter.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EISFILTERED%3C%2FFONT%3E('Date'%5BYear%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3ECALCULATE%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3EDISTINCTCOUNT%3C%2FFONT%3E('Date'%5BYear%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3EFILTER%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3EALL%3C%2FFONT%3E('Date'%5BDate%5D)%2C%5BDate%5D%20%26lt%3B%3D%20%3CFONT%20color%3D%22%230000FF%22%3EMAX%3C%2FFONT%3E('CDC%20Pop%20Rated%20UV%20Irradiance'%5BDate%5D)%20%26amp%3B%26amp%3B%20%5BDate%5D%20%26gt%3B%3D%20%3CFONT%20color%3D%22%2333CCCC%22%3EMinDate%3C%2FFONT%3E))%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculate%20the%20number%20of%20years%20leading%20up%20to%20and%20including%20the%20current%20year.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EBLANK%3C%2FFONT%3E()%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Return%20a%20blank%20if%20other%20columns%20are%20used%20on%20the%20axis.%3C%2FFONT%3E%0A)%3C%2FPRE%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CPRE%3E%3CSTRONG%3Ei380%20Avg%3C%2FSTRONG%3E%20%3D%20%3CFONT%20color%3D%22%230000FF%22%3EAVERAGE%3C%2FFONT%3E(%5Bi380%5D)%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20An%20average%20of%20the%20values%20in%20a%20column%20on%20the%20Fact%20table.%20This%20could%20also%20be%20a%20SUM%20or%20some%20other%20sort%20of%20calculated%20measure%20that%20you%20are%20putting%20on%20an%20axis.%3C%2FFONT%3E%3C%2FPRE%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CDIV%3E%0A%3CPRE%3E%3CSTRONG%3Ei380%20Avg%20Prev%3C%2FSTRONG%3E%20%3D%20%2F%2F*%20A%20calculation%20of%20the%20previous%20calculation%20on%20the%20axis.%20%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3Evar%3C%2FFONT%3E%20%3CFONT%20color%3D%22%2333CCCC%22%3EWeekIndexPrev%3C%2FFONT%3E%20%3D%20%3CFONT%20color%3D%22%230000FF%22%3EMAX%3C%2FFONT%3E('Date'%5BWeek%20Index%5D)%20-%201%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20A%20variable%20for%20the%20Index%20of%20the%20previous%20week.%20Time%20Intelligence%20doesn't%20work%20at%20the%20week%20level%2C%20so%20this%20is%20only%20needed%20if%20you%20want%20to%20have%20weekly%20values%20on%20the%20axis.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3ERETURN%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3ESWITCH%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3ETRUE%3C%2FFONT%3E()%2C%3CBR%20%2F%3E%3CFONT%20color%3D%22%23800080%22%3E%5BRun%20Count%20(X)%5D%3C%2FFONT%3E%20%26lt%3B%201%2C%3CFONT%20color%3D%22%230000FF%22%3EBLANK%3C%2FFONT%3E()%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Don't%20show%20any%20values%20if%20either%201)%20the%20current%20member%20on%20the%20axis%20is%20the%20first%20one%2C%20or%202)%20the%20current%20member%20is%20not%20on%20the%20axis%20of%20the%20visual.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EISFILTERED%3C%2FFONT%3E('Date'%5BWeek%20Year%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3ECALCULATE%3C%2FFONT%3E(%3CFONT%20color%3D%22%23800080%22%3E%5Bi380%20Avg%5D%3C%2FFONT%3E%2C%3CFONT%20color%3D%22%230000FF%22%3EFILTER%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3EALL%3C%2FFONT%3E('Date')%2C'Date'%5BWeek%20Index%5D%20%3D%20%3CFONT%20color%3D%22%2333CCCC%22%3EWeekIndexPrev%3C%2FFONT%3E))%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculate%20the%20i380%20Avg%20for%20the%20previous%20week.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EISFILTERED%3C%2FFONT%3E('Date'%5BMonth%20Year%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3ECALCULATE%3C%2FFONT%3E(%3CFONT%20color%3D%22%23800080%22%3E%5Bi380%20Avg%5D%3C%2FFONT%3E%2C%3CFONT%20color%3D%22%230000FF%22%3EPREVIOUSMONTH%3C%2FFONT%3E('Date'%5BDate%5D))%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculate%20the%20i380%20Avg%20for%20the%20previous%20month.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EISFILTERED%3C%2FFONT%3E('Date'%5BQuarter%20Year%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3ECALCULATE%3C%2FFONT%3E(%3CFONT%20color%3D%22%23800080%22%3E%5Bi380%20Avg%5D%3C%2FFONT%3E%2C%3CFONT%20color%3D%22%230000FF%22%3EPREVIOUSQUARTER%3C%2FFONT%3E('Date'%5BDate%5D))%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculate%20the%20i380%20Avg%20for%20the%20previous%20quarter.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EISFILTERED%3C%2FFONT%3E('Date'%5BYear%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3ECALCULATE%3C%2FFONT%3E(%3CFONT%20color%3D%22%23800080%22%3E%5Bi380%20Avg%5D%3C%2FFONT%3E%2C%3CFONT%20color%3D%22%230000FF%22%3EPREVIOUSYEAR%3C%2FFONT%3E('Date'%5BDate%5D))%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculate%20the%20i380%20Avg%20for%20the%20previous%20year.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EBLANK%3C%2FFONT%3E()%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Return%20a%20blank%20if%20other%20columns%20are%20used%20on%20the%20axis.%3C%2FFONT%3E%3CBR%20%2F%3E)%3C%2FPRE%3E%0A%3C%2FDIV%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CPRE%3E%3CFONT%20color%3D%22%2399CC00%22%3E%3CFONT%20color%3D%22%23000000%22%3E%3CSTRONG%3ERise%3C%2FSTRONG%3E%20%3D%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculate%20the%20delta%20(change)%20of%20the%20calculated%20measure%20between%20the%20current%20and%20previous%20Months%20on%20the%20axis.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3ESWITCH%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3ETRUE()%3C%2FFONT%3E%2C%3CBR%20%2F%3E%3CFONT%20color%3D%22%23800080%22%3E%5BRun%20Count%20(X)%5D%3C%2FFONT%3E%20%26lt%3B%3D%201%2C%26nbsp%3B%3CFONT%20color%3D%22%230000FF%22%3EBLANK()%3C%2FFONT%3E%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Don't%20show%20any%20values%20if%20either%201)%20the%20current%20member%20on%20the%20axis%20is%20the%20first%20one%2C%20or%202)%20the%20current%20member%20is%20not%20on%20the%20axis%20of%20the%20visual.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%23800080%22%3E%5Bi380%20Avg%5D%3C%2FFONT%3E%20-%20%3CFONT%20color%3D%22%23800080%22%3E%5Bi380%20Avg%20Prev%5D%3C%2FFONT%3E)%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FPRE%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CPRE%3E%3CSTRONG%3EAvg%20Rise%20(M)%3C%2FSTRONG%3E%20%3D%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculate%20the%20average%20rise%20for%20the%20entire%20series%20of%20data.%3C%2FFONT%3E%20%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3ESWITCH%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3ETRUE%3C%2FFONT%3E()%2C%3CBR%20%2F%3E%3CFONT%20color%3D%22%23800080%22%3E%5BRun%20Count%20(X)%5D%3C%2FFONT%3E%20%26lt%3B%201%2C%3CFONT%20color%3D%22%230000FF%22%3EBLANK%3C%2FFONT%3E()%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Don't%20show%20any%20values%20if%20either%201)%20the%20current%20member%20on%20the%20axis%20is%20the%20first%20one%2C%20or%202)%20the%20current%20member%20is%20not%20on%20the%20axis%20of%20the%20visual.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EISFILTERED%3C%2FFONT%3E('Date'%5BWeek%20Year%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3ECALCULATE%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3EAVERAGEX%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3ESUMMARIZE%3C%2FFONT%3E('Date'%2C'Date'%5BWeek%20Year%5D)%2C%3CFONT%20color%3D%22%23800080%22%3E%5BRise%5D%3C%2FFONT%3E)%2C%3CFONT%20color%3D%22%230000FF%22%3EALLSELECTED%3C%2FFONT%3E('Date'))%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculate%20the%20average%20rise%20at%20the%20week%20level%20for%20all%20dates%20that%20have%20been%20selected.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EISFILTERED%3C%2FFONT%3E('Date'%5BMonth%20Year%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3ECALCULATE%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3EAVERAGEX%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3ESUMMARIZE%3C%2FFONT%3E('Date'%2C'Date'%5BMonth%20Year%5D)%2C%3CFONT%20color%3D%22%23800080%22%3E%5BRise%5D%3C%2FFONT%3E)%2C%3CFONT%20color%3D%22%230000FF%22%3EALLSELECTED%3C%2FFONT%3E('Date'))%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculate%20the%20average%20rise%20at%20the%20month%20level%20for%20all%20dates%20that%20have%20been%20selected.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EISFILTERED%3C%2FFONT%3E('Date'%5BQuarter%20Year%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3ECALCULATE%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3EAVERAGEX%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3ESUMMARIZE%3C%2FFONT%3E('Date'%2C'Date'%5BQuarter%20Year%5D)%2C%3CFONT%20color%3D%22%23800080%22%3E%5BRise%5D%3C%2FFONT%3E)%2C%3CFONT%20color%3D%22%230000FF%22%3EALLSELECTED%3C%2FFONT%3E('Date'))%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculate%20the%20average%20rise%20at%20the%20quarter%20level%20for%20all%20dates%20that%20have%20been%20selected.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EISFILTERED%3C%2FFONT%3E('Date'%5BYear%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3ECALCULATE%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3EAVERAGEX%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3ESUMMARIZE%3C%2FFONT%3E('Date'%2C'Date'%5BYear%5D)%2C%3CFONT%20color%3D%22%23800080%22%3E%5BRise%5D%3C%2FFONT%3E)%2C%3CFONT%20color%3D%22%230000FF%22%3EALLSELECTED%3C%2FFONT%3E('Date'))%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculate%20the%20average%20rise%20at%20the%20year%20level%20for%20all%20years%20that%20have%20been%20selected.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EBLANK%3C%2FFONT%3E()%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Return%20a%20blank%20if%20other%20columns%20are%20used%20on%20the%20axis.%3C%2FFONT%3E%3CBR%20%2F%3E)%3C%2FPRE%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CPRE%3E%3CFONT%20color%3D%22%23000000%22%3E%3CSTRONG%3EY%20Intercept%20(B)%3C%2FSTRONG%3E%20%3D%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculating%20the%20Y%20intercept%2C%20which%20is%20the%20value%20of%20the%20regression%20line%20when%20it%20crosses%20zero%20on%20the%20x%20axis.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3ESWITCH%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3ETRUE%3C%2FFONT%3E()%2C%3CBR%20%2F%3E%3CFONT%20color%3D%22%23800080%22%3E%5BRun%20Count%20(X)%5D%3C%2FFONT%3E%20%26lt%3B%201%2C%3CFONT%20color%3D%22%230000FF%22%3EBLANK%3C%2FFONT%3E()%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Don't%20show%20any%20values%20if%20either%201)%20the%20current%20member%20on%20the%20axis%20is%20the%20first%20one%2C%20or%202)%20the%20current%20member%20is%20not%20on%20the%20axis%20of%20the%20visual.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EISFILTERED%3C%2FFONT%3E('Date'%5BWeek%20Year%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3ECALCULATE%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3EAVERAGEX%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3ESUMMARIZE%3C%2FFONT%3E('Date'%2C'Date'%5BWeek%20Year%5D)%2C(%3CFONT%20color%3D%22%23800080%22%3E%5Bi380%20Avg%5D%3C%2FFONT%3E%20-%20(%3CFONT%20color%3D%22%23800080%22%3E%5BAvg%20Rise%20(M)%5D%3C%2FFONT%3E%20*%20%3CFONT%20color%3D%22%23800080%22%3E%5BRun%20Count%20(X)%5D%3C%2FFONT%3E)))%2C%3CFONT%20color%3D%22%230000FF%22%3EALLSELECTED%3C%2FFONT%3E('Date'))%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculate%20the%20Y%20intercept%20at%20the%20week%20level%20(the%20B%20in%20Y%20%3D%20MX%20%2B%20B)%20by%201)%20calculating%20the%20(Rise%20*%20Run)%20and%20then%20subtracting%20it%20from%20the%20i380%20average%20and%202)%20averaging%20all%20of%20those%20values.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EISFILTERED%3C%2FFONT%3E('Date'%5BMonth%20Year%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3ECALCULATE%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3EAVERAGEX%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3ESUMMARIZE%3C%2FFONT%3E('Date'%2C'Date'%5BMonth%20Year%5D)%2C(%3CFONT%20color%3D%22%23800080%22%3E%5Bi380%20Avg%5D%3C%2FFONT%3E%20-%20(%3CFONT%20color%3D%22%23800080%22%3E%5BAvg%20Rise%20(M)%5D%3C%2FFONT%3E%20*%20%3CFONT%20color%3D%22%23800080%22%3E%5BRun%20Count%20(X)%5D%3C%2FFONT%3E)))%2C%3CFONT%20color%3D%22%230000FF%22%3EALLSELECTED%3C%2FFONT%3E('Date'))%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculate%20the%20Y%20intercept%20at%20the%20month%20level%20(the%20B%20in%20Y%20%3D%20MX%20%2B%20B)%20by%201)%20calculating%20the%20(Rise%20*%20Run)%20and%20then%20subtracting%20it%20from%20the%20i380%20average%20and%202)%20averaging%20all%20of%20those%20values.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EISFILTERED%3C%2FFONT%3E('Date'%5BQuarter%20Year%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3ECALCULATE%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3EAVERAGEX%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3ESUMMARIZE%3C%2FFONT%3E('Date'%2C'Date'%5BQuarter%20Year%5D)%2C(%3CFONT%20color%3D%22%23800080%22%3E%5Bi380%20Avg%5D%3C%2FFONT%3E%20-%20(%3CFONT%20color%3D%22%23800080%22%3E%5BAvg%20Rise%20(M)%5D%3C%2FFONT%3E%20*%20%3CFONT%20color%3D%22%23800080%22%3E%5BRun%20Count%20(X)%5D%3C%2FFONT%3E)))%2C%3CFONT%20color%3D%22%230000FF%22%3EALLSELECTED%3C%2FFONT%3E('Date'))%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculate%20the%20Y%20intercept%20at%20the%20quarter%20level%20(the%20B%20in%20Y%20%3D%20MX%20%2B%20B)%20by%201)%20calculating%20the%20(Rise%20*%20Run)%20and%20then%20subtracting%20it%20from%20the%20i380%20average%20and%202)%20averaging%20all%20of%20those%20values.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EISFILTERED%3C%2FFONT%3E('Date'%5BYear%5D)%2C%3CFONT%20color%3D%22%230000FF%22%3ECALCULATE%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3EAVERAGEX%3C%2FFONT%3E(%3CFONT%20color%3D%22%230000FF%22%3ESUMMARIZE%3C%2FFONT%3E('Date'%2C'Date'%5BYear%5D)%2C(%3CFONT%20color%3D%22%23800080%22%3E%5Bi380%20Avg%5D%3C%2FFONT%3E%20-%20(%3CFONT%20color%3D%22%23800080%22%3E%5BAvg%20Rise%20(M)%5D%3C%2FFONT%3E%20*%20%3CFONT%20color%3D%22%23800080%22%3E%5BRun%20Count%20(X)%5D%3C%2FFONT%3E)))%2C%3CFONT%20color%3D%22%230000FF%22%3EALLSELECTED%3C%2FFONT%3E('Date'))%2C%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Calculate%20the%20Y%20intercept%20at%20the%20year%20level%20(the%20B%20in%20Y%20%3D%20MX%20%2B%20B)%20by%201)%20calculating%20the%20(Rise%20*%20Run)%20and%20then%20subtracting%20it%20from%20the%20i380%20average%20and%202)%20averaging%20all%20of%20those%20values.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EBLANK%3C%2FFONT%3E()%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Return%20a%20blank%20if%20other%20columns%20are%20used%20on%20the%20axis.%3C%2FFONT%3E%3CBR%20%2F%3E)%3C%2FFONT%3E%3C%2FPRE%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CPRE%3E%3CSTRONG%3ERegression%20(Y)%3C%2FSTRONG%3E%20%3D%20(%3CFONT%20color%3D%22%23800080%22%3E%5BAvg%20Rise%20(M)%5D%3C%2FFONT%3E%20*%20%3CFONT%20color%3D%22%23800080%22%3E%5BRun%20Count%20(X)%5D%3C%2FFONT%3E)%20%2B%20%3CFONT%20color%3D%22%23800080%22%3E%5BY%20Intercept%20(B)%5D%3C%2FFONT%3E%20%3CFONT%20color%3D%22%2399CC00%22%3E%2F%2F*%20Complete%20the%20(Y%20%3D%20MX%20%2B%20B)%20equation%20for%20your%20regression!%20%3C%2FFONT%3E%3C%2FPRE%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%20is%20a%20diagram%20detailing%20how%20the%20above%20seven%20DAX%20expressions%20interact%20with%20each%20other%20as%20you%20stack%20them%20together%20like%20building%20blocks%3A%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22regressionDAXexpressions.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F297462i9BF90E49B63541AE%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22regressionDAXexpressions.png%22%20alt%3D%22Custom%20DAX%20Calculations%20are%20used%20as%20components%20of%20other%20DAX%20calculations%20to%20complete%20the%20Equation%20and%20make%20it%20dynamic%20for%20multidimensional%20queries.%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3ECustom%20DAX%20Calculations%20are%20used%20as%20components%20of%20other%20DAX%20calculations%20to%20complete%20the%20Equation%20and%20make%20it%20dynamic%20for%20multidimensional%20queries.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20you've%20added%20these%20custom%20DAX%20expressions%20to%20your%20solution%20you%20can%20not%20only%20plot%20a%20Regression%20line%20at%20multiple%20levels%20of%20a%20Date%20Hierarchy%2C%20but%20also%20bubble%20up%20areas%20of%20opportunity%20in%20your%20data.%20In%20the%20example%20below%2C%20Counties%20can%20be%20bubbles%20up%20that%20have%20the%20most%20dramatic%20increase%20in%20%5BAvg%20Rise%20(M)%5D%20which%20means%20that%20they%20have%20the%20greatest%20upward%20trend%20over%20time.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22BubbleUpRegression.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F299195iAE0B09C39AEE6001%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22BubbleUpRegression.png%22%20alt%3D%22Linear%20Regression%20Line%20Slope%20(M)%20can%20be%20used%20to%20Bubble%20Up%20Steeply%20Increasing%20or%20Decreasing%20slices%20of%20data.%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3ELinear%20Regression%20Line%20Slope%20(M)%20can%20be%20used%20to%20Bubble%20Up%20Steeply%20Increasing%20or%20Decreasing%20slices%20of%20data.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3EIn%20Healthcare%20you%20could%20bubble%20up%20the%20trends%20of%20measures%20such%20as%20%3CEM%3ELength%20of%20Stay%2C%20Complication%20Rates%2C%20Fall%20Rates%2C%20Compliance%20Rates%2C%20Discharge%20by%20Noon%20Rates%3C%2FEM%3E%20to%20answer%20questions%20such%20as%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3EWhich%20Specialties%20are%20showing%20the%20greatest%20upwards%20or%20downwards%20trends%3F%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3EWhat%20Floors%20of%20the%20building%20are%20trending%3F%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3EWhich%20DRGs%20are%20trending%20the%20wrong%20way%3F%20What%20if%20we%20drill%20into%20the%20data%20and%20compare%20the%20trends%20of%20the%20bad%20DRGs%20by%20Shift%20or%20Primary%20Diagnoses%3F%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EHere%20is%20a%20video%20describing%20the%20process%20and%20utility%20of%20a%20custom%20linear%20regression%20trendline%20using%20DAX%20in%20Power%20BI%3A%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3C%2FP%3E%3CDIV%20class%3D%22video-embed-center%20video-embed%22%3E%3CIFRAME%20class%3D%22embedly-embed%22%20src%3D%22https%3A%2F%2Fcdn.embedly.com%2Fwidgets%2Fmedia.html%3Fsrc%3Dhttps%253A%252F%252Fwww.youtube.com%252Fembed%252FwWSdQ4FItkM%253Ffeature%253Doembed%26amp%3Bdisplay_name%3DYouTube%26amp%3Burl%3Dhttps%253A%252F%252Fwww.youtube.com%252Fwatch%253Fv%253DwWSdQ4FItkM%26amp%3Bimage%3Dhttps%253A%252F%252Fi.ytimg.com%252Fvi%252FwWSdQ4FItkM%252Fhqdefault.jpg%26amp%3Bkey%3Db0d40caa4f094c68be7c29880b16f56e%26amp%3Btype%3Dtext%252Fhtml%26amp%3Bschema%3Dyoutube%22%20width%3D%22600%22%20height%3D%22337%22%20scrolling%3D%22no%22%20title%3D%22YouTube%20embed%22%20frameborder%3D%220%22%20allow%3D%22autoplay%3B%20fullscreen%22%20allowfullscreen%3D%22true%22%3E%3C%2FIFRAME%3E%3C%2FDIV%3E%3CP%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2405245%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22Regression1.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F298699i067F66F4F5E3933C%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Regression1.png%22%20alt%3D%22Regression1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ECreating%20Custom%20Linear%20Regression%20DAX%20calculations%20enables%20trendspotting%2C%20forecasting%2C%20and%20pattern%20identification%20to%20bubble%20up%20areas%20on%20need%20of%20focus%20and%20action.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2405245%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPower%20BI%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Jul 29 2021 06:56 AM
Updated by:
www.000webhost.com