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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
kristel_tulio
Helper III
Helper III

DIvided by Zero error when loading

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)

2 ACCEPTED SOLUTIONS

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
	)

 

View solution in original post

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.

 

xifeng_L_0-1715738007848.png

 

Or you can use try ... otherwise ... statement to protect the division operation, for example:

 

xifeng_L_1-1715738247011.png

 

 

Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !

 

Thank you~

 

View solution in original post

5 REPLIES 5
kristel_tulio
Helper III
Helper III

Hi @xifeng_L and @aduguid ,

 

Thank you for your response. I tried to do both of your suggestion but it didn't work on my report. And upon checking with our developer it seems it's an issue in our SQL database.

xifeng_L
Super User
Super User

Can you provide more details, such as error messages?

Here is the error message

kristel_tulio_0-1715728258874.png

 

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.

 

xifeng_L_0-1715738007848.png

 

Or you can use try ... otherwise ... statement to protect the division operation, for example:

 

xifeng_L_1-1715738247011.png

 

 

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
	)

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.