Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Hi, I would like to ask how to fix the Divided by zero error when loading the report? I suspect this calculation is the reason. I hope you can help me with it. Thank you
z Payments Calculated Amount =
SWITCH( TRUE(),
[Line Amount Types] = "Inclusive" && [Type] = "ACCREC",
(([Line Amount]-[Tax Amount]) * DIVIDE( [PaymentAmount] , [Invoice Total] )),
[Line Amount Types] = "Exclusive" && [Type] = "ACCREC",
(([Line Amount]) * DIVIDE( [PaymentAmount] , [Invoice Total] )),
[Line Amount Types] = "NoTax" && [Type] = "ACCREC",
(([Line Amount]) * DIVIDE( [PaymentAmount] , [Invoice Total] )),
[Line Amount Types] = "Inclusive" && [Type] = "ACCPAY",
(0-([Line Amount]-[Tax Amount]) * DIVIDE( [PaymentAmount] , [Invoice Total] )),
[Line Amount Types] = "NoTax" || [Line Amount Types] = "NoTax" && [Type] = "ACCPAY",
((0-[Line Amount]) * DIVIDE( [PaymentAmount] , [Invoice Total] )),
[Line Amount Types] = "Exclusive" || [Line Amount Types] = "NoTax" && [Type] = "ACCPAY",
((0-[Line Amount]) * DIVIDE( [PaymentAmount] , [Invoice Total] )),
0)
Solved! Go to Solution.
You can try to pass in the 3rd parameter as 0 for the DIVIDE function. e.g.
DIVIDE(<numerator>, <denominator> [,<alternateresult>])
z Payments Calculated Amount =
SWITCH( TRUE()
, [Line Amount Types] = "Inclusive" && [Type] = "ACCREC"
, (([Line Amount]-[Tax Amount]) * DIVIDE( [PaymentAmount] , [Invoice Total], 0 ))
, [Line Amount Types] = "Exclusive" && [Type] = "ACCREC"
, (([Line Amount]) * DIVIDE( [PaymentAmount] , [Invoice Total], 0 ))
, [Line Amount Types] = "NoTax" && [Type] = "ACCREC"
, (([Line Amount]) * DIVIDE( [PaymentAmount] , [Invoice Total], 0 ))
, [Line Amount Types] = "Inclusive" && [Type] = "ACCPAY"
, (0-([Line Amount]-[Tax Amount]) * DIVIDE( [PaymentAmount] , [Invoice Total], 0 ))
, [Line Amount Types] = "NoTax" || [Line Amount Types] = "NoTax" && [Type] = "ACCPAY"
, ((0-[Line Amount]) * DIVIDE( [PaymentAmount] , [Invoice Total], 0 ))
, [Line Amount Types] = "Exclusive" || [Line Amount Types] = "NoTax" && [Type] = "ACCPAY"
, ((0-[Line Amount]) * DIVIDE( [PaymentAmount] , [Invoice Total], 0 )),0
)
Hi @kristel_tulio ,
This issue you are having is occurring during the process of getting data using PowerQuery, not as a result of PowerBI or DAX.
It may be that the query is simple, making the query collapsed, which will be passed to the SQL database for calculation, and dividing by 0 inside the SQL database will report an error.
An easy way to do this is to use the "Detect Data type" feature to change the datatype of all fields immediately after the navigation step in PowerQuery, so that the query does not collapse, the calculations are handled in PowerQuery, and PowerQuery does not report an error when dividing by zero.
Or you can use try ... otherwise ... statement to protect the division operation, for example:
Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !
Thank you~
Can you provide more details, such as error messages?
Here is the error message
Hi @kristel_tulio ,
This issue you are having is occurring during the process of getting data using PowerQuery, not as a result of PowerBI or DAX.
It may be that the query is simple, making the query collapsed, which will be passed to the SQL database for calculation, and dividing by 0 inside the SQL database will report an error.
An easy way to do this is to use the "Detect Data type" feature to change the datatype of all fields immediately after the navigation step in PowerQuery, so that the query does not collapse, the calculations are handled in PowerQuery, and PowerQuery does not report an error when dividing by zero.
Or you can use try ... otherwise ... statement to protect the division operation, for example:
Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !
Thank you~
You can try to pass in the 3rd parameter as 0 for the DIVIDE function. e.g.
DIVIDE(<numerator>, <denominator> [,<alternateresult>])
z Payments Calculated Amount =
SWITCH( TRUE()
, [Line Amount Types] = "Inclusive" && [Type] = "ACCREC"
, (([Line Amount]-[Tax Amount]) * DIVIDE( [PaymentAmount] , [Invoice Total], 0 ))
, [Line Amount Types] = "Exclusive" && [Type] = "ACCREC"
, (([Line Amount]) * DIVIDE( [PaymentAmount] , [Invoice Total], 0 ))
, [Line Amount Types] = "NoTax" && [Type] = "ACCREC"
, (([Line Amount]) * DIVIDE( [PaymentAmount] , [Invoice Total], 0 ))
, [Line Amount Types] = "Inclusive" && [Type] = "ACCPAY"
, (0-([Line Amount]-[Tax Amount]) * DIVIDE( [PaymentAmount] , [Invoice Total], 0 ))
, [Line Amount Types] = "NoTax" || [Line Amount Types] = "NoTax" && [Type] = "ACCPAY"
, ((0-[Line Amount]) * DIVIDE( [PaymentAmount] , [Invoice Total], 0 ))
, [Line Amount Types] = "Exclusive" || [Line Amount Types] = "NoTax" && [Type] = "ACCPAY"
, ((0-[Line Amount]) * DIVIDE( [PaymentAmount] , [Invoice Total], 0 )),0
)
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
25 | |
12 | |
9 | |
9 | |
9 |
User | Count |
---|---|
19 | |
14 | |
14 | |
13 | |
12 |