Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
Hi everyone,
I'm working on a DAX measure that performs a linear regression on cost data and then predicts the cost for the end of the current month. I'm using the LINESTX function to calculate the slope and intercept of the regression line. Below is the code I'm working with:
LinestX =
VAR azcost_agg =
SUMMARIZECOLUMNS(
azcost_f[DT_DATE],
azcost_f[ID_SUBSCRIPTION],
FILTER(
azcost_f,
azcost_f[DT_DATE] >= DATE(YEAR(TODAY()), 1, 1)
),
"TotalCost", SUM(azcost_f[N_CostInBillingCurrency])
)
-- Apply the LINESTX function and extract coefficients
VAR cost_prediction =
ADDCOLUMNS(
LINESTX(azcost_agg, [TotalCost], [DT_DATE]),
"Slope", SELECTCOLUMNS(LINESTX(azcost_agg, [TotalCost], [DT_DATE]), "Slope1", [Slope1]),
"Intercept", SELECTCOLUMNS(LINESTX(azcost_agg, [TotalCost], [DT_DATE]), "Intercept", [Intercept])
)
-- Extract specific values
VAR slope = MAXX(cost_prediction, [Slope1])
VAR intercept = MAXX(cost_prediction, [Intercept])
-- Calculate the prediction for the end of the current month
VAR prediction = slope * EOMONTH(TODAY(), 0) + intercept
RETURN
prediction
Any insights or suggestions would be greatly appreciated! Thanks in advance for your help.
@IHOUM , To ensure that the measure respects user-selected filters, you should use ALLSELECTED or REMOVEFILTERS to control the context in which the regression is calculated. This will allow the measure to dynamically recalculate based on the filters applied in the report.
LinestX =
VAR azcost_agg =
SUMMARIZECOLUMNS(
azcost_f[DT_DATE],
azcost_f[ID_SUBSCRIPTION],
"TotalCost", SUM(azcost_f[N_CostInBillingCurrency])
)
-- Apply the LINESTX function and extract coefficients
VAR cost_prediction =
LINESTX(azcost_agg, [TotalCost], [DT_DATE])
-- Extract specific values
VAR slope = MAXX(cost_prediction, [Slope])
VAR intercept = MAXX(cost_prediction, [Intercept])
-- Calculate the prediction for the end of the current month
VAR prediction = slope * EOMONTH(TODAY(), 0) + intercept
RETURN
prediction
Proud to be a Super User! |
|
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
Check out the February 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 61 | |
| 59 | |
| 42 | |
| 18 | |
| 15 |
| User | Count |
|---|---|
| 109 | |
| 101 | |
| 39 | |
| 29 | |
| 29 |