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
Anonymous
Not applicable

How to calculated logirothemic regression manually using DAX?

How to calculate logarithemic regression : Y = a + b * ln (X)  ?

@MFelix 

8 REPLIES 8
Anonymous
Not applicable

@MFelix@v-kelly-msft  Below code is used for log regression 

LogTrend-A-MB = 
VAR Known =
FILTER (
SELECTCOLUMNS (
CALCULATETABLE ( VALUES ( ConsumptionDate[DateNumber] ), ALLSELECTED (ConsumptionDate) ),
"Known[X]", 'ConsumptionDate'[DateNumber],
"Known[Y]", PatientsNormalized[A-MB]
),
AND ( NOT ( ISBLANK ( Known[X] ) ), NOT ( ISBLANK ( Known[Y] ) ) )
)
VAR Count_Items =
COUNTROWS ( Known )
VAR Sum_X =
SUMX ( Known, Known[X] )
VAR Sum_X2 =
SUMX ( Known, Known[X] ^ 2 )
VAR Sum_Y =
SUMX ( Known, Known[Y] )
VAR Sum_XY =
SUMX ( Known, Known[X] * Known[Y] )
VAR Average_X =
AVERAGEX ( Known, Known[X] )
VAR Average_Y =
AVERAGEX ( Known, Known[Y] )
VAR Slope =
DIVIDE (
Count_Items * Sum_XY - Sum_X * Sum_Y,
Count_Items * Sum_X2 - Sum_X ^ 2
)
VAR Intercept = Average_Y
- Slope * Average_X
RETURN
SUMX( DISTINCT ( ConsumptionDate[DateNumber] ),
LN(Intercept + Slope * ConsumptionDate[DateNumber])
)
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

You can use "LOG10" function in dax expression:

Y=a+b*LOG10(X)

 

Here is the link for reference:

https://docs.microsoft.com/en-us/dax/log10-function-dax

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Anonymous
Not applicable

Hi @v-kelly-msft ,

 

I calculated using below dax but same value repeated (i.e returned same value for every row).

Log A-MB = 
VAR Known =
FILTER (
SELECTCOLUMNS (
CALCULATETABLE ( VALUES ( ConsumptionDate[DateNumber] ), ALLSELECTED (ConsumptionDate) ),
"Known[X]", 'ConsumptionDate'[DateNumber],
"Known[Y]", PatientsNormalized[A-MB]
),
AND ( NOT ( ISBLANK ( Known[X] ) ), NOT ( ISBLANK ( Known[Y] ) ) )
)
VAR Count_Items =
COUNTROWS ( Known )
VAR Sum_X =
SUMX ( Known, Known[X] )
VAR Sum_X2 =
SUMX ( Known, Known[X] ^ 2 )
VAR Sum_Y =
SUMX ( Known, Known[Y] )
VAR Sum_XY =
SUMX ( Known, Known[X] * Known[Y] )
VAR Average_X =
AVERAGEX ( Known, Known[X] )
VAR Average_Y =
AVERAGEX ( Known, Known[Y] )
VAR Slope =
DIVIDE (
Count_Items * Sum_XY - Sum_X * Sum_Y,
Count_Items * Sum_X2 - Sum_X ^ 2
)
VAR Intercept = Average_Y
- Slope * Average_X
RETURN
SUMX( DISTINCT ( ConsumptionDate[DateNumber] ),
Intercept + Slope * LOG10(ConsumptionDate[DateNumber])
)

 Please help me on this. 

Hi @Anonymous,

 

What does the below expression represent for?

 FILTER (
        SELECTCOLUMNS (
            CALCULATETABLE (
                VALUES ( ConsumptionDate[DateNumber] ),
                ALLSELECTED ( ConsumptionDate )
            ),
            "Known[X]", 'ConsumptionDate'[DateNumber],
            "Known[Y]", PatientsNormalized[A-MB]
        )

Does there any error return?

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Anonymous
Not applicable

That code block is used to get idividual rows of the table.

No errors code is working as expected.

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

Hi @Anonymous ,

 

So your issue is solved now?

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Anonymous
Not applicable

No @v-kelly-msft still waiting..

MFelix
Super User
Super User

Hi @Anonymous ,

 

I'm calling out to @Greg_Deckler because he has done a lot of examples for this type of situations not sure if he has done it for logotithemic.

 

@Greg_Deckler did you do Logarithicm on your extense DAX calculations?


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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.