Forum Discussion

Sureshot's avatar
Sureshot
Icon for Helper I rankHelper I
8 years ago
Solved

DAX expression I cannot get to work - please help.

 

 

 

 

 

 

 

 

 

 

 

Hi.

My first post.

So I have a matrix and on this matrix I am trying to calculate in DAX a field called % of Premium.

Please see pic above, for 2017 the % of Premium value for the Liability section should be 22.14% (175607198 / 793274434)

However given the following DAX formula I get 33.61% (175607198 / 52638561)

 

% of Premium = SUM('Agency Scorecard 3'[Earned Premium]) / CALCULATE(SUM('Agency Scorecard 3'[Earned Premium]), ALLSELECTED())

 

You may be asking why I'm not using SQL to do this and the fact is that running this calculation over SQL will get me spurious results. I really need to use the row total Power BI is using.

 

Please help.

  • Here's what worked but I don't understand why!

    I just added the red part and all worked.

     

    % of Premium = DIVIDE(SUM('Agency Scorecard 3'[Earned Premium]), CALCULATE(SUM('Agency Scorecard 3'[Earned Premium]), ALLEXCEPT('Agency Scorecard 3','Agency Scorecard 3'[Loss Year]),'Agency Scorecard 3'[Summary Line ID],'Business Division'[BusinessDivisionID], VALUES('Business Division'[BusinessDivisionID])), 0)

     

    Thanks all for your help in getting me on the right track.

     

    Here's the post that explains why the Values function works so now I know.

    https://community.powerbi.com/t5/Desktop/ALLEXCEPT-only-working-on-visible-row-context/td-p/18030

     

    You keep adding for all your report (might work with page/visualisation filters I don;t know) filters as follows:

     

    % of Premium = DIVIDE(SUM('Agency Scorecard 3'[Earned Premium]), CALCULATE( SUM('Agency Scorecard 3'[Earned Premium]), ALLEXCEPT('Agency Scorecard 3','Agency Scorecard 3'[Loss Year]),'Agency Scorecard 3'[Summary Line ID],'Business Division'[BusinessDivisionID], VALUES('Business Division'[BusinessDivisionID]), VALUES('Agent'[Agent Alternate 1]), VALUES('Agent'[Agent Alternate 2]), VALUES('Sub Producer'[Alt Sub Producer 2]), VALUES('Managing Unit'[Managing Unit Name]), VALUES(Office[Office]), VALUES('Product Line'[Product Line Name]), VALUES(Underwriter[Underwriter Name]) ),0)

9 Replies

    • Sureshot's avatar
      Sureshot
      Icon for Helper I rankHelper I

      Hi. Thanks but that gave 7.28% for the example I gave. I donlt even know how 7.28% is caculated.

      • Zubair_Muhammad's avatar
        Zubair_Muhammad
        Icon for Community Champion rankCommunity Champion

        Hi Sureshot

         

        Actually ALLSELECTED works on Totals. It does not impact Row and Column filters

         

        Could you share your file via googledrive or onedrive?