Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
edward_engler
Regular Visitor

DIVIDE won't accept calculation as denominator

I have a developed a report relating to risk management that compares risks left over from 2023 and monitors progress as those risks are resolved. You can see that the gauge in the screenshot is showing the total percent accurately, which is simply dividing the count of backlog risks processed (1139) by the static total backlog count from end of last year (3451).

edward_engler_0-1712942671528.png

I made a measure to break this percent out by month as shown in the bar chart in the screenshot:

Backlog Variance % = 
DIVIDE(
CALCULATE(DISTINCTCOUNT(risk_table[risk_id]), PARALLELPERIOD(date_table[date_dt],-1,MONTH)) --Prev Month Risk Count
-
CALCULATE(DISTINCTCOUNT(risk_table[risk_id]), risk_table[snapshot_dt] = MAX(risk_table[snapshot_dt])) --Current Risk Count
,
CALCULATE(DISTINCTCOUNT(risk_table[risk_id]), risk_table[snapshot_dt] = DATE(2023, 12, 31))) --Denominator calc

However, this measure ends up giving me a completely blank monthly chart:

edward_engler_1-1712942814208.png

BUT if I hardcode that measure denominator to 3451 like this:

Backlog Variance % = 
DIVIDE(
CALCULATE(DISTINCTCOUNT(risk_table[risk_id]), PARALLELPERIOD(date_table[date_dt],-1,MONTH)) --Prev Month Risk Count
-
CALCULATE(DISTINCTCOUNT(risk_table[risk_id]), risk_table[snapshot_dt] = MAX(risk_table[snapshot_dt])) --Current Risk Count
,
3451) --hardcoded denominator

... then it produces the correct percentages!

edward_engler_2-1712942943461.png

The hardcoded denominator is not a long-term solution of course because I need this chart to respond properly to filters. Why is it that the DIVIDE function works with a static number in the denominator but not with a calc that should be giving the exact same value? (That calc I'm using in the denominator works perfectly fine for the card in the top left to give me the 3,451 total, btw.)

 

1 ACCEPTED SOLUTION
edward_engler
Regular Visitor

Hello, after a lot of tinkering and trying a few things, I got the calculation to work properly. The denominator needed to have the date field from the CALENDAR table:

Backlog Variance % = 
DIVIDE(
CALCULATE(DISTINCTCOUNT(risk_table[risk_id]), PARALLELPERIOD(date_table[date_dt],-1,MONTH)) --Prev Month Risk Count
-
CALCULATE(DISTINCTCOUNT(risk_table[risk_id]), risk_table[snapshot_dt] = MAX(risk_table[snapshot_dt])) --Current Risk Count
,
CALCULATE(DISTINCTCOUNT(risk_table[risk_id]), calendar_table[date] = DATE(2023, 12, 31))) --Denominator

However, I'm not sure WHY that fixed it. Can someone explain to me why I was getting a divide-by-zero error when using the calendar snapshot date from the risk table?

View solution in original post

3 REPLIES 3
edward_engler
Regular Visitor

Hello, after a lot of tinkering and trying a few things, I got the calculation to work properly. The denominator needed to have the date field from the CALENDAR table:

Backlog Variance % = 
DIVIDE(
CALCULATE(DISTINCTCOUNT(risk_table[risk_id]), PARALLELPERIOD(date_table[date_dt],-1,MONTH)) --Prev Month Risk Count
-
CALCULATE(DISTINCTCOUNT(risk_table[risk_id]), risk_table[snapshot_dt] = MAX(risk_table[snapshot_dt])) --Current Risk Count
,
CALCULATE(DISTINCTCOUNT(risk_table[risk_id]), calendar_table[date] = DATE(2023, 12, 31))) --Denominator

However, I'm not sure WHY that fixed it. Can someone explain to me why I was getting a divide-by-zero error when using the calendar snapshot date from the risk table?

Idrissshatila
Super User
Super User

Hello @edward_engler ,

 

try putting the calc in a variable and reference it in the denominator.



Did I answer your question? Mark my post as a solution! Appreciate your Kudos
Follow me on LinkedIn linkedIn
Vote for my Community Mobile App Idea

Proud to be a Super User!




Hi @Idrissshatila , thanks for your reply!
I did as suggested:

Backlog Variance % = 
VAR denominator = CALCULATE(DISTINCTCOUNT('risk_table'[risk_id]), risk_table[snapshot_dt] = DATE(2023, 12, 31))
RETURN
DIVIDE(
CALCULATE(DISTINCTCOUNT(risk_table[risk_id]), PARALLELPERIOD(calendar_table[date_dt],-1,MONTH)) --Prev Month Risk Count
-
CALCULATE(DISTINCTCOUNT('risk_table'[risk_id]), risk_table[snapshot_dt] = MAX(risk_table[snapshot_dt])) --Current Risk Count
,
denominator --variable
)

But unfortuantely I got the same result with a blank chart:

edward_engler_0-1712945350076.png

One thing that I noted is that if I put anything into the "If divide by zero" safety parameter, the chart always defaults to that value. In this case I entered "1" for that value:

edward_engler_1-1712945468186.png

For some reason, using my calc in the denominator, even as a variable, results in a "divide by zero" situation but I don't understand how.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.