Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.
Hello there,
I am new to dax and I have a set of formulas that work but the grand total is wrong:
First is the main formula:
(1)
Solved! Go to Solution.
It looks like you're dealing with a common issue in DAX (Data Analysis Expressions) where the total at the grand total level is not aggregating correctly. This is often referred to as the "non-additive grand total error."
The problem usually arises when you have measures that rely on row context, and the aggregation at the total level does not correctly consider this context. In your case, it might be related to the use of the MAX function in the Policy Period measure.
Here are a few suggestions to help you overcome this issue:
Use AVERAGEX for Policy Period: Instead of using MAX to get a single value for Policy Period, you can use AVERAGEX to iterate over the rows and calculate the average. Since there's only one row context for Policy, it will effectively return the same value at the row level and the total level.
Policy Period =
AVERAGEX(ALL(Policy), DATEDIFF(Policy[InceptionDate], Policy[ExpiryDate], DAY))
Modify the Net Earned Premiums Measure: Try modifying the Net Earned Premiums measure to use SUMX over the Policy table instead of the CarrierContract table.
Net Earned Premiums =
SUMX(
VALUES(Policy[PolicyId]),
([Net Written Premiums]/[Policy Period])*[Days On Cover]
)
This assumes there is a relationship between the CarrierContract and Policy tables.
Use VALUES in Days On Cover: Modify the Days On Cover measure to use VALUES for Policy. This ensures that the context transition from row context to filter context is handled correctly.
Days On Cover =
VAR Days_Since_Inception = DATEDIFF(MAX(Policy[InceptionDate]), TODAY(), DAY)
RETURN IF(Days_Since_Inception <= [Policy Period], Days_Since_Inception, [Policy Period])
becomes
Days On Cover =
VAR Days_Since_Inception = DATEDIFF(MAX(Policy[InceptionDate]), TODAY(), DAY)
RETURN IF(Days_Since_Inception <= VALUES(Policy[Policy Period]), Days_Since_Inception, VALUES(Policy[Policy Period]))
Try incorporating these changes and see if they resolve the issue. Always remember to test thoroughly with your data to ensure the correctness of the results.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.
You haven't mentioned what the "row level" is in your report. Is it time periods, like months?
I see two related issues in the measures that make them not useable in certain contexts, like grand totals:
First the use of the today function. If you are reporting periods you would want to use the maximium date of the current date context instead of today. Also, for determining the [Days on cover] you would want to check if the inception date is on or after the minimum date of the reporting period.
It looks like you're dealing with a common issue in DAX (Data Analysis Expressions) where the total at the grand total level is not aggregating correctly. This is often referred to as the "non-additive grand total error."
The problem usually arises when you have measures that rely on row context, and the aggregation at the total level does not correctly consider this context. In your case, it might be related to the use of the MAX function in the Policy Period measure.
Here are a few suggestions to help you overcome this issue:
Use AVERAGEX for Policy Period: Instead of using MAX to get a single value for Policy Period, you can use AVERAGEX to iterate over the rows and calculate the average. Since there's only one row context for Policy, it will effectively return the same value at the row level and the total level.
Policy Period =
AVERAGEX(ALL(Policy), DATEDIFF(Policy[InceptionDate], Policy[ExpiryDate], DAY))
Modify the Net Earned Premiums Measure: Try modifying the Net Earned Premiums measure to use SUMX over the Policy table instead of the CarrierContract table.
Net Earned Premiums =
SUMX(
VALUES(Policy[PolicyId]),
([Net Written Premiums]/[Policy Period])*[Days On Cover]
)
This assumes there is a relationship between the CarrierContract and Policy tables.
Use VALUES in Days On Cover: Modify the Days On Cover measure to use VALUES for Policy. This ensures that the context transition from row context to filter context is handled correctly.
Days On Cover =
VAR Days_Since_Inception = DATEDIFF(MAX(Policy[InceptionDate]), TODAY(), DAY)
RETURN IF(Days_Since_Inception <= [Policy Period], Days_Since_Inception, [Policy Period])
becomes
Days On Cover =
VAR Days_Since_Inception = DATEDIFF(MAX(Policy[InceptionDate]), TODAY(), DAY)
RETURN IF(Days_Since_Inception <= VALUES(Policy[Policy Period]), Days_Since_Inception, VALUES(Policy[Policy Period]))
Try incorporating these changes and see if they resolve the issue. Always remember to test thoroughly with your data to ensure the correctness of the results.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.
Hi,
I want to say you are a hero!
Simply just modifying the net earned premiums has fixed the issue!
Thanks!
Check out the November 2023 Power BI update to learn about new features.
Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.
Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!