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
Fcoatis
Post Patron
Post Patron

Hard time figuring out context

Hello all,

Hard time to get the result expected. 

Fig1.png

Every variable has been checked but the problem seem to be the context of "Base" in SUMX:

 

Fig2.png

The result expected is the value of Covar in Table1 and what I´m getting is Covar2. I checked the sum of colum .Covar2 in excel and its equal to the expected value Covar. The context is ruled by the date slicer and Asset Filter.

 

Any help would be fully appreciated.

 

1 ACCEPTED SOLUTION
Fcoatis
Post Patron
Post Patron

Here is what I ended up.

 

.Covar = 
VAR Tabela =
    FILTER(
        SELECTCOLUMNS(
            ALLSELECTED(Base[Date]),
            "LnAsset",  [.ln],
            "LnIBOV", CALCULATE([.ln],Base[Asset]="IBOV")
        ),
        AND (
            NOT( ISBLANK( [LnAsset])),
            NOT ( ISBLANK( [LnIBOV] ))
        )
    ) 
VAR Denom = COUNTROWS(Tabela)-1
VAR Res = SUMX(Tabela, ([LnAsset]-AVERAGEX(Tabela,[LnAsset]))*([LnIBOV]-AVERAGEX(Tabela,[LnIBOV]))/Denom)
RETURN
Res

View solution in original post

4 REPLIES 4
Fcoatis
Post Patron
Post Patron

Here is what I ended up.

 

.Covar = 
VAR Tabela =
    FILTER(
        SELECTCOLUMNS(
            ALLSELECTED(Base[Date]),
            "LnAsset",  [.ln],
            "LnIBOV", CALCULATE([.ln],Base[Asset]="IBOV")
        ),
        AND (
            NOT( ISBLANK( [LnAsset])),
            NOT ( ISBLANK( [LnIBOV] ))
        )
    ) 
VAR Denom = COUNTROWS(Tabela)-1
VAR Res = SUMX(Tabela, ([LnAsset]-AVERAGEX(Tabela,[LnAsset]))*([LnIBOV]-AVERAGEX(Tabela,[LnIBOV]))/Denom)
RETURN
Res
Greg_Deckler
Super User
Super User

@Fcoatis I'm not understanding your use of SUMX here. Result being a variable will always be the same value so I do not believe SUMX(Base,Result) should be any different than just Result. Perhaps you meant to create a table variable and use ADDCOLUMS with the Result calculation as a column in the table and then SUMX across it?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler thanks for your answer. I just wanted to add all the values of Result. When I just called Var Result it didnt show the expected value ( -0.0000795701 ). I´m missing the table variable. Just fyi the SUMX(Base, Result) and just Result returned diferent values. I can share the pbix if you like. Thanks again.

@Fcoatis PBIX would definitely help. 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.