In this Microsoft Power BI Tutorial, We will discuss how we can fix error “Power BI NaN (Not a number) while dividing by Zero“.
In Power BI Desktop, I have a table named as Income Tax Rates which has below columns as:
- Country (Choice Data type)
- Net Wage Earnings After Tax (Currency Data type)
- Income Tax Rate (Number Data type)
- Employee Social Security Contributions (Number Data type)
- Net Wage Bonus (Currency Data type)
As per my requirement, I wanted to calculate the total Income Tax Variance (Income Tax Rate/Employee Social Security Contributions) of Iceland whose rank is 3 like the below screenshot.
In the Power BI Desktop, Get the SharePoint List from SharePoint Online Site to your Power BI Desktop. Follow the below link to get the SharePoint List to Power BI Desktop:
Load SharePoint List to Power BI Desktop
Now format the columns which are having different Data types in Power BI Desktop. In the below screenshot, I have changed the below column Data types as:
- Employee Social Security Contributions (Whole Number)
- Income Tax Rate (Whole Number)
- Net Wage Bonus (Whole Number)
- Net Wage Earnings After Tax (Whole Number)
Now I have retrieved the Column (Employee Social Security Contribution) value of Country (Iceland) by using the below Power BI measure formula:
Similarly, I have retrieved the Column (Income Tax Rate) value of Country (Iceland) by using the below Power BI measure formula:
And then I have divided these above columns to get the total variance of Country (Iceland). For that, I have used this below Power BI measure formula.
While I have added the Measure [Total Income Variance (Iceland)] in a Card visual, then the result was appearing as NaN which you can see in the below screenshot.
Power BI NaN (Not a number) while dividing by Zero
Basically, In the Power BI Desktop, We are getting the error NaN when we are dividing the value as 0 by 0.
To resolve this NaN issue, We have to follow these below steps:
Step-1:
First of all, Go to the Home tab and then click on Edit Queries from the ribbon. Select Edit Queries from the drop-down as shown below.
Step-2:
Once you will click on the Edit Queries option, then the below query editor window will appear. In this window, Go to the Add Column tab and then Click on Custom Column.
Step-3:
Now a Custom Column window will appear where you have to write the Custom Column Query formula for the error NaN.
Enter a new column name and put the below Query formula in Custom column formula field:
Income Variance= if Number.IsNaN(0/0) then 0 else 1
- Here, New column name = Income Variance
- Custom column formula = if Number.IsNaN(0/0) then 0 else 1
By using a double click, you can insert the Available columns if you want otherwise click on OK Button as like below screenshot.
Step-4:
Now you can see the new custom column(Income Variance) will be created in the Query Editor window.
After that, do not forget to click on the Close & Apply button. Go to the Home tab and click on Close & Apply option as like the below figure.
Step-5:
Now to test the new custom column, Take a Card under the Visualizations section and insert the custom column (Income Variance) into the Fields section of the card. Then in the Card, you can see the value will be appearing as 0.
As per my requirement, I wanted the Income Variance field as Percentage variance, that’s why I have formatted the data type as Percentage.
Also, You may like following Power BI tutorials:
- Power BI report using People Picker Field
- Microsoft Power BI Error: This content isn’t available
- Access to the resource is forbidden error in Power BI
- [Video Tutorial] Create Power BI Dashboard step by step tutorial
- DAX Filter function (Text column) in Power BI
- Power BI Measure Sum and Subtract Example
- Get Current Month Sales Report using Power BI Measure
- Get Next Month Sales Report in Power BI
- Data Labels in Power BI
- Subtraction in Power bi using DAX
- Power BI Group By Examples
- Power bi shared dataset permissions management
- Scheduled Power BI report data refresh
- How to change data source in Power Bi
Hence in this Microsoft Power BI Tutorial, We discussed how to fix error “Power BI NaN (Not a number) while dividing by Zero“.
Hello Everyone!! I am Bhawana a SharePoint MVP and having about 10+ years of SharePoint experience as well as in .Net technologies. I have worked in all the versions of SharePoint from wss to Office 365. I have good exposure in Customization and Migration using Nintex, Metalogix tools. Now exploring more in SharePoint 2016 🙂 Hope here I can contribute and share my knowledge to the fullest. As I believe “There is no wealth like knowledge and no poverty like ignorance”
Hi,
Is there an easy way to manage NaN or Infinity ?
I tried to replace error, no impact.
I tried to replace «NaN» by 0, no impact (when it’s working with Null).
In my formula I tried with «try a/b otherwise 0» but I still have the error.
I saw some test based on Number.IsNaN but it just tests NaN… what about Infinity or other errors…
The only way I found is to test Numerator and denominator (if Numerator=0 or Denominator = 0 then 0 else …. ), but maybe there is a better methodology like an equivalent to IFERROR in Excel?
Thank you for your help.
(I’m using PowerQuery in Excel, so I don’t have DAX measures & operators).
Александр L Hello Everyone!! I am Bhawana a SharePoint MVP and having about 10+ years of SharePoint experience as well as in .Net technologies. I have worked in all the versions of SharePoint from wss to Office 365. I have good exposure in Customization and Migration using Nintex, Metalogix tools. Now exploring more in SharePoint 2016 🙂 Hope here I can contribute and share my knowledge to the fullest. As I believe “There is no wealth like knowledge and no poverty like ignorance” Hi, Is there an easy way to manage NaN or Infinity ? I tried to replace error, no impact. I tried to replace «NaN» by 0, no impact (when it’s working with Null). In my formula I tried with «try a/b otherwise 0» but I still have the error. I saw some test based on Number.IsNaN but it just tests NaN… what about Infinity or other errors… The only way I found is to test Numerator and denominator (if Numerator=0 or Denominator = 0 then 0 else …. ), but maybe there is a better methodology like an equivalent to IFERROR in Excel? Thank you for your help. (I’m using PowerQuery in Excel, so I don’t have DAX measures & operators).
P B Member Members Forum Posts: 38 Member Since:
1 April 22, 2021 — 9:01 am
Hello Mynda, What is the best approach to handle NaN Errors in Power Query? I have a table which is using a couple of columns but I am concerned about 2 Columns for this calculation and that is A and B and the calculation is to be in %. The Formula my company is using is like this =A2/(A2+B2) This calculation will go into the 3rd column. And now there are some records where values are zero. So two issues over here. When I Close and Load to the Table it will show me 4 errors and if I click on 4 Errors and it takes me back to PQ and over there it shows me those records where all values are zero in these 2 columns and 3rd column will show an error, NaN. I used a Custom Column and used this Formula =A2/(A2+B2) (Replacing it with actual column names). Is there a better way to do this? How do I change Values for NaN Errors? I can’t replace Values of NaN with anything else. I wanted to put value like Undetermined or Undefined (That is what it is when you divide with 0) Please advise Thanks, PB Mynda Treacy Admin Forum Posts: 4526 Member Since:
2 April 22, 2021 — 4:10 pm
Hi PB, There is a function for NaN values which you can use in a custom column: = if Number.IsNaN([A]/([A]+[B])) then null else [A]/([A]+[B]) Mynda P B Member Members Forum Posts: 38 Member Since:
3 April 22, 2021 — 9:42 pm
Hello Mynda, Thank you! I will try it right now. Thanks, PB Hi team, Today I really got a big headache of » Invalid cell value » error. I got a table with 44 small tables and each small table look like this: Each of these small tables get same structure and all the data types are correct and without any errors However, when I try to expand these small tables and make them into a big table, I got the error message: [DataFormat.Error] Invalid cell value ‘#N/A’. I tried to use remove error function or replace error function while those ways are dead end and refuse to work. Where does the error come from and how can I fix it? The following query is the code before expand table and it works without anything wrong: let in »This line above is the procedure to setup 44 small table listed in above picture #»Removed Other Columns2″ = Table.SelectColumns(nc,{«NTB»}), » This line is the expand line and after this line get the error message when I choose a column and click «load more» button in Cheers, Tom Sun |