Error Handling for Log formula

M10Ant

New Member
Joined
Dec 30, 2021
Messages
36
Office Version
  1. 365
Platform
  1. Windows
Hello

I have a list of numbers in a "Data" column and a column to the right of it that divides the LOG of that value by the SUM of the LOG of each value in the entire Data column:
=LOG([@Data])/SUM(LOG([Data]))

This works fine as long as there are no values in the [Data] column with a value of "0". If there are, this results in the entire second column displaying "#NUM!". The error is expected and caused by "LOG(0)". I simply need a way to substitute "LOG(0)" for "0" for any zero Data value rows so that the formula still results in giving me calculation values for any non-zero Data values instead of "#NUM!".

My current workaround requires two calculation columns instead of one. This is shown in the table on the right. First, the [LOG] column calculates the LOG of each Data value that is not equal to zero. If the Data value is a zero, it puts a 0 in the column. The second column then does the job of dividing the current row's [LOG] column value by the SUM of the [LOG] column values

Just looking to see if anyone knows a solution that can be done in a single calculation column - some kind of merge of the formulas I have in the two columns in the right-most table? I think It would still need to incorporate the IF statement to handle zero Data values, but also have have some kind of inbuilt expanding total to the SUM part of the calculation. I just can't work out how to do it, or if it's even possible. Thanks in advance.

Log.xlsx
ABCDEF
1
2Workaround to prevent "#NUM!" when any Data values are "0"
3DataLog of Data / SUM of Log of DataLogLog of Data / SUM of Log of Data
43239020.08205.510413630.0820
54234340.08385.6267857270.0838
636864580.09776.566609290.0977
7271439430.11077.4336729350.1107
8962196580.11887.9832638090.1188
9148783038680.151410.172553420.1514
10308170240.11157.4887906970.1115
11844710230.11807.9267077540.1180
122948247530.12618.4695639430.1261
Sheet1
Cell Formulas
RangeFormula
E4:E12E4=IF(Table1[@Data]=0,0,LOG(Table1[@Data]))
F4:F12F4=[@Log]/SUM([Log])
C4:C12C4=LOG([@Data])/SUM(LOG([Data]))
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
How about
Excel Formula:
=IF([@Data]=0,0,LOG([@Data]))/SUM(IF([Data]=0,0,LOG([Data])))
 
Upvote 0
Solution
Thank you Fluff :) That's exactly it. I was getting something close to that, but not good enough!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,697
Messages
6,173,895
Members
452,536
Latest member
Chiz511

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