Forum Discussion

NLC's avatar
NLC
Frequent Visitor
9 years ago
Solved

DAX SUMX REFERENCE ANOTHER TABLE

Hi everyone, So I am making a portfolio report in power Bi. I am currently trying to get an average return for an industry and display it in a line chart, with the date on the x axis, and return o...
  • MattAllington's avatar
    9 years ago

    Your original formula wont work because you are missing a calculate to force context transition.  Check out my evaluation contexts video here https://exceleratorbi.com.au/my-mdis-presentations/

     

     

    industryreturn =
    SUMX (
        'Portfolio',
        CALCULATE (
            AVERAGE ( 'Historical Prices'[Close] ) * ( 'Portfolio'[Shares] )
                / ( 'Portfolio'[Cost basis] )
                - 1
        )
            * 'Portfolio'[Shares]
    )
        / CALCULATE ( SUM ( 'Portfolio'[Shares] ) )