Forum Discussion
Linear regression on UNION data
Hi IvoM ,
Please try using the REMOVEFILTERS function in the measure to remove the context filter.
TestForecastSixM-3+3TrendLine =
VAR _EndDate1 = EOMONTH(TODAY(), -1)
VAR _StartDate1 = EOMONTH(_EndDate1, -3) + 1
VAR _StartDate2 = EOMONTH(TODAY(), -1) + 1
VAR _EndDate2 = EOMONTH(_StartDate2, 2)
VAR CombinedData =
UNION(
SUMMARIZECOLUMNS(
DimCalendar[YYYY-MM],
FILTER(
ALL(DimCalendar[Date]),
DimCalendar[Date] >= _StartDate1 && DimCalendar[Date] <= _EndDate1
),
FILTER(
ALL(DimPartProductFamily),
DimPartProductFamily[FamilyType] = "Výroba"
),
"Qty", SUM(FactsTransactionOOREC[Qty])
),
SUMMARIZECOLUMNS(
DimCalendar[YYYY-MM],
FILTER(
ALL(DimCalendar[Date]),
DimCalendar[Date] >= _StartDate2 && DimCalendar[Date] <= _EndDate2
),
FILTER(
ALL(DimPartProductFamily),
DimPartProductFamily[FamilyType] = "Výroba"
),
"Qty", [ForecastSixMSumQtyNewestBackup]
)
)
VAR CombinedDataWithRank =
ADDCOLUMNS(
CombinedData,
"Rank", RANKX(CombinedData, [YYYY-MM], , ASC, DENSE)
)
VAR AllCombinedDataWithRank =
CALCULATETABLE(
CombinedDataWithRank,
REMOVEFILTERS(DimCalendar),
REMOVEFILTERS(DimPartProductFamily)
)
VAR RegressionResult =
LINESTX(
AllCombinedDataWithRank,
[Qty], [Rank], TRUE
)
VAR Intercept = MAXX(RegressionResult, [Intercept])
VAR Slope = MAXX(RegressionResult, [Slope1])
VAR CurrentRank = MAXX(CombinedDataWithRank, [Rank])
RETURN
Intercept + Slope * CurrentRank
Please try it and let me know if it helps, and if it doesn't, please provide a Power BI Desktop file in progress (with sensitive information removed) that fully covers your issue or question in a usable format (not a screenshot). You can upload the PBIX file to a cloud storage service such as OneDrive, Google Drive (set up public access), SharePoint, or a Github repository, and then share the URL of the file.
If you have any other questions please feel free to contact me.
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
Hey Anonymous
Thank you for your quick response! I tried your proposed solution, but unfortunately, it doesn’t change the result of the measure.
The issue seems to be that every measure I try is still being evaluated row by row.
Here is the link to the PBIX file—I’ve removed all unnecessary information. Even though it's a completely new file, the behavior remains the same.
Test1.pbix
Thanks again for your help!
Edit: The table aproach also disable filtering based on Contract, PartNo and PartProductFamily which is not ideal.