# Looking for a udf to calculate numerator

#### michaelsmith559

##### Well-known Member
I have a sheet setup to calculate a naive bayes estimate. I am looking for a udf that can calculate the numerator for me as I have a lot of values to check and this part is manually too time consuming. The udf needs to ignore cells that contain a zero. What I want to be able to do is in cell BL18 and cell BM19 enter something like =numerator(select my range of cells) and then get an output like the current formulas give me. See sheet below:

#### pgc01

##### MrExcel MVP
Hi

You don't need a udf, you can use a formula.
Test the values in BL11:BL17 and discard the products where they are 0, like in B18:

=PRODUCT(IF(BL11:BL17,BL11:BL17^{1,0}*N(OFFSET(BF2,(ROW(B11:B17)-ROW(B11))*5+{0,1},))^{-1,1}))

This is an array formula, you have to confirm it with CTRL-SHIFT-ENTER

#### michaelsmith559

##### Well-known Member
The formula works for the values shown in BM1:BM8. When I change the values, to the next value to evaluate, the value returned using the formula in BL18 returns: 3.18385E-08 and your formula returns: 2.49388E-09.

<colgroup><col width="107"></colgroup><tbody>
</tbody>

#### pgc01

##### MrExcel MVP
The formula works for the values shown in BM1:BM8. When I change the values, to the next value to evaluate, the value returned using the formula in BL18 returns: 3.18385E-08 and your formula returns: 2.49388E-09.

Sorry, I don't understand: "When I change the values, to the next value to evaluate"

You mean you have new values in BL11:BL17? which are they?

#### michaelsmith559

##### Well-known Member
Also, it looks like when I put the formula into BL19, it works for calculating the numerator for BL18. When I move the formula to BM19 and calculate BM18, it gives different results.

#### michaelsmith559

##### Well-known Member
I am going to post another sheet.

#### michaelsmith559

##### Well-known Member
<b>Note: Do not try and enter the {} manually yourself</b></td></tr></table><br />

#### pgc01

##### MrExcel MVP
I see.

Well, the formulas you are using in BL18 and BM18 are not doing the same thing.

In BL18 you choose in each group of 3 values in column BF the second and the first values and you divide them and multiply the result by the corresponding value in column BL.
In BM18 you choose in each group of 3 values in column BF the third and the first values and you divide them and multiply the result by the corresponding value in column BM.

This means that in the formula in BM you have to use an offset of 2 instead of 1

{=PRODUCT(IF(BM11:BM17,BM11:BM17^{1,0}*N(OFFSET(BF2,(ROW(B11:B17)-ROW(B11))*5+{0,2},))^{-1,1}))}

{

#### michaelsmith559

##### Well-known Member
Thank you so much. Solved the problem great.

#### pgc01

##### MrExcel MVP
You're welcome. I'm glad it helped.

### Forum statistics

1,082,323
Messages
5,364,584
Members
400,809
Latest member
formulasataglance

### This Week's Hot Topics

• populate from drop list with multiple tables
Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
• Find list of words from sheet2 in sheet1 before a comma and extract text vba
Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
• Dynamic Formula entry - VBA code sought
Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...