Copy column if value is number

ElisabethC

New Member
Joined
Mar 14, 2017
Messages
4
Hi,

I would like to compare column A and column B and calculate how much % B is of A.
So I added column C with formula "=B/A"
However some of the values in A and B are 0, which result in a statement "Not a number" in column C.
Unfortunately pivot tables can't handle this as a value.

So I tried to add column D that would copy C's value and would set 0 instead of "Not a number".
I used this formula, but it seems to be incorrect:
=IF([column C]="NaN (Not a number)";"0";"column C]")

Can anybody help with the formula? Or maybe I don't need column D and solve my base problem in another way?

Thanks!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Welcome to the Board!

Since you cannot divide by zero, when column A is zero, that would cause an error or problem.
So try entering this for your formula in column C (this example assuming row 2), which will return a zero whenever column A is zero (instead of an error or message):
Code:
=IF(A2=0,0,B2/A2)
 
Upvote 0
If this is happening in Power Query (as this s the Power BI forum), then you can use

=if Number.IsNaN([Column C]) then 0 else [Column C]
 
Upvote 0
Thanks for the help! That's exactly what I was looking for!



Hi,

I would like to compare column A and column B and calculate how much % B is of A.
So I added column C with formula "=B/A"
However some of the values in A and B are 0, which result in a statement "Not a number" in column C.
Unfortunately pivot tables can't handle this as a value.

So I tried to add column D that would copy C's value and would set 0 instead of "Not a number".
I used this formula, but it seems to be incorrect:
=IF([column C]="NaN (Not a number)";"0";"column C]")

Can anybody help with the formula? Or maybe I don't need column D and solve my base problem in another way?

Thanks!
 
Upvote 0
My mistake. Didn't realize I was in the Power BI forum.
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,824
Members
449,190
Latest member
rscraig11

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top