Forum Discussion
DAX expression I cannot get to work - please help.
- 8 years ago
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)
Have you tried using:
% of Premium = SUM('Agency Scorecard 3'[Earned Premium]) / CALCULATE(SUM('Agency Scorecard 3'[Earned Premium]), ALLSELECTED('Agency Scorecard 3'[Earned Premium]))?
For the row you've selected, you need to tell it what should remain unfiltered. Your expression (ALLSELECTED()) is telling it to unfilter everything which results in the % of total, not row.
Thanks I tried that but it gave me 100% as 175607198 divided by itself is 1.
Is there a way to calculate the row total dynamically in DAX or somehow grab the 793274434 number as the divisor?
- Sureshot8 years ago
Helper I
So I've tried the following which works if I change my underlying query to only point at the business division I have set in the report filter. Also if I remove that report filter it works. What is that about?
% of Premium = 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])
- tjd8 years ago
Impactful Individual
Sorry that didn't work for you. The article at https://www.sqlbi.com/articles/understanding-allselected/ helped me to better understand how to generate a correct row total DAX expression. Especially when I realized you could have multiple ALLSELECTED (Table[Column]) statements in a CALCULATE statement. I just had to play around a bit and was able to solve it with my set up. Since I don't know how your data is really set up, I can't help you.
- Sureshot8 years ago
Helper I
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)