Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
codyraptor
Resolver I
Resolver I

Correct Total of Product using Linear Regression %

I have a measure that calculates the Linear Fcst %.   The measure works perfect and I get the correct results by month.  I need to take forecast values and multiply against the linear regression %.  Simply taking Fcst * Regress % works perfectly fine within a given month, but the total column does not work.  I've tried SUMX( values(Date[month]), Fcst*Regress), but the Linear Regression % reverts to looking at only the selected month.  I basically lose my forecasted values because the Linear Regression % gets iterated over an individual month.  I hope that makes sense.  Any help is greatly appreciated...

 

In the below pic...  Booked Sales Linear is correct by month...but the 560,638 is incorrect.

Total Booked Sales Linear has the correct total...but the by month is incorrect.

codyraptor_0-1661555086398.png

 

Below is the blog post providing the fcst logic.

https://xxlbi.com/blog/simple-linear-regression-in-dax/

 

3 REPLIES 3
daXtreme
Solution Sage
Solution Sage

To calculate the correct regression values in the individual cells you have to use ALLSELECTED in its body because ALLSELECTED lets you look at all the selected something you have put on the colums, not only on the individual value in the column.

Yep...I'm using allselected in the measure to caluclate the correct regression.  It's just when I go to use 'sumx(months, fcst*regression %)'...it seems to remove the 'all selected' within the regression measure.  

That's most likely because you should never use any measure with ALLSELECTED in it in an iterator. There are many reasons for this limitation and you can find articles about this on www.sqlbi.com. Check this one out: The definitive guide to ALLSELECTED - SQLBI

 

For the time being I don't have time to look at this in full depth but I'll try to find some time later on. But you should definitely read the article above. ALLSELECTED measures should always be only top-level measures. Sadly, this is not the case in your code and this very likely is the problem.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors