Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers!
Enter the sweepstakes now!See when key Fabric features will launch and what’s already live, all in one place and always up to date. Explore the new Fabric roadmap
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
)
User | Count |
---|---|
19 | |
18 | |
16 | |
13 | |
13 |
User | Count |
---|---|
9 | |
8 | |
8 | |
7 | |
6 |