Newsroom Update

New features come to Apple services this fall. Learn more >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Help sought with SUMPRODUCT from an Excel Sheet and displaying only rows containing data?

Not sure if anyone can help here, looking for some help with trying to get a sheet I have opened in Numbers from Excel. One of the cells has a formula in using SUMPRODUCT which I understand Numbers does not support (or at least not this use of it).


Essentially the cell here is looking to see what rows in a sheet are occupied by a number from 1-99 and where they are, count those then perform a second sum of dividing the total by 2 and rounding up.


The formula from Excel is:


INT((SUMPRODUCT((A14:A47≠"")÷COUNTIF(A14:A47,A14:A47&""))+1)÷2)



A warning I am getting is:


The range A14:A47 can't be used as a single value



I wondered if Numbers needs to use the SUMIF function and whether if written correctly, with the right syntax, it could be made to work?



Also, is anyone aware of any option in Numbers to display only rows which have data entries for printing (e.g. excluding blank rows which may be scattered randomly down the sheet)?

Posted on Sep 23, 2020 5:07 PM

Reply
Question marked as Best reply

Posted on Sep 24, 2020 8:04 PM

You can select the rows you don't want to see, right click, and hide them. After printing, unhide them. It isn't automatic but it will hide them without having to delete rows.


Alternatively, rework the sheet so it does not have vertically merged cells. Filters will then be usable.

9 replies

Sep 24, 2020 6:16 PM in response to TechAddict

Thanks for the comments so far. I've attached a picture below from the Excel spreadsheet. It's not the full width sheet as, IMO, it's not too well designed and needs a big / wide screen to use it with ease. As such I've used Freeze Row/Column and scrolled out the columns that are not relevant.


It's essentially a List Builder designed by a team who produce war-game rules. Problem being there is no native Mac version and Numbers needs a different formula for this one particular calculation. The column A contains the input the formula needs to check for with only the rows that have an entry needing to be counted. There is a slight problem however in that it's not simply a case of checking whether there's any content at all, rather it needs to check a) if there is any content and b) count any cells that have the same value entry as one. Thus, in the attached image you can see that the the rows are numbered 1,1,2,2,3,3,4,5,6,7. This is because the 'pairs' of numbers are actually the same unit (each with different stats) but they need to be counted as just one unit (or 3 in this case vs 6). Once the calculation is made it needs to divide by two and round up if there is an odd number. In the example given the result would be 7 units or 'counts', divided by two and rounded up, so 4. If the total 'count' is 10 the result will be 5. The result then populates the cell, in this case, the merged P6 cell with the red fill.


Previously this would have been no problem for me as I would haver simply opened it in Excel on 'Office for Mac 2011' but since that ceased to function (I believe after the move to 64 Bit?) I have not really needed the extra functionality of Excel so haven't replaced it. As I may also soon need a Windows machine I don't intend to. So rather than use work arounds like free office software which I've always found pretty clunky, I'd rather just try and create a Numbers version which I could do IF I could figure how to write a formula that would work in Numbers. I actually have the sheet in Numbers, it's just that one cell that won't populate.


As I mentioned in the earlier post, the added problem is that the Excel version uses some kind of filter on the Print Sheet (which is populated from this Input sheet) to only display rows that contain inputted data. With the liberal use of Merge Cells in this sheet I can also not fathom a way, other than manually deleting rows, to have Numbers do the same. That said, even if I could gate the first problem solved it would be better for me than using my current work around.



Sep 24, 2020 7:48 PM in response to TechAddict

More rambling followed by how I would replicate the formula in Numbers. It appears I decoded it correctly.


One problem with trying to replicate the formula in Numbers is IEEE 754 binary math. If there are three of a number, each gets assigned the number 1/3. The number 1/3 cannot be created exactly, it is represented as 0.3333333333333330. Add three of them together in Numbers and you don't get exactly 1, you get 0.9999999999999990. You have to display a lot of decimals to see this. This will throw off the rest of the math. In Excel, that little error is corrected and you do get 1 exactly. However, in Excel if you actually have the numbers 0.3333333333333330 and added three of them, the result might be 1 or 0.9999999999999990 depending on how you created those numbers. You have to be aware of these things when dealing with decimal numbers and fractions. They can mess things up. Excel and Numbers don't always do the same thing.


ROUND can fix that little math error in Numbers but I don't like relying on it. Or maybe there are only 1 or 2 of a number so the problem with 1/3 never comes up. The replicated formula, which actually requires a column of formulas, would be:

B14 =IF(A14<>"",1/COUNTIF(A$14:A$47,A14),"")

fill down to B47

The formula for summing these results and doing the rest of the math =INT((ROUND(SUM(B14:B47),0)+1)/2)


A better set of formulas that does not have any math issues, and is simpler too, would be

B14 =COUNTIF(A$14:A14,A14)=1

fill down to B47

The formula for summing these results and doing the rest of the math =INT((COUNTIF(B14:B47, TRUE)+1)/2)


Hide column B after it is all set up.

If you add more rows, the formula in column B will automatically fill to the new rows. If you always add those new rows by inserting rows above row 47, the summation formula will adjust to include the new rows.

You don't have to use column B for the column of formulas, you can do this in a column far off to the right if you want to.


Back to rambling, below is Excel giving two different results for the same numbers. The 0.333's in column C were pasted formula results from a cell that had 1/3 in it. Column D I typed in the numbers. Column E = C-D and it equals 0 exactly, indicating that C and D have the exact same numbers in them. But the sums at the bottom of C and D are obviously different.




Sep 24, 2020 8:14 AM in response to TechAddict

what rows in a sheet are occupied by a number from 1-99 and where they are, count those then perform a second sum of dividing the total by 2 and rounding up.


INT((SUMPRODUCT((A14:A47≠"")÷COUNTIF(A14:A47,A14:A47&""))+1)÷2)


I have to think out loud to put this together. You don't have to read it, just skip to the end with what I think this formula's results actually are.


(A14:A47≠"") is the same as having a column of formulas next to A14-A47 starting with =IF(A14<>"",TRUE,FALSE). It creates an internal array vs having a column in the table. It is an array indicating whether that row had a value in it or not. TRUE will be treated as a 1 and FALSE as 0 in the math formula coming up.


COUNTIF(A14:A47,A14:A47&"") is, I believe, the same as having a column of formulas next to A14-A47 starting with =COUNTIF(A$14:A$47,A14&"") which counts how many of that particular value are found in A14-A47. So if A14-A47 had five values equal to "2", those five rows would get a "5" from this formula.


Dividing the first by the second is like dividing "is there a value in this row (1 if there is, 0 if not)" by "how many of this value are in A14-A47".


The SUMPRODUCT is not really doing a "sumproduct", it is just doing a simple sum of all those answers. I think SUMPRODUCT might be necessary for Excel to do this "array formula" type of formula.


INT rounds down, not up.


So if there were five values equal to 2, each of them would have TRUE in the first array and "5" in the second. The result of the division for each row would be 1/5 and the sum of those results would be 1. The formula then adds another "1" to it and divides by 2 for a final result of 1. If there had been two different values in A14-A47 it would have summed to 2 then + 1 = 3 then divided by 2 = 1.5 and INT = 1.


From what I can tell, then, if there is one unique value in A14-A47 the result should be 1, if two unique values then 1, if 3 unique values then 2, if 4 unique values then 2, etc.. It is not looking for any particular values, there is nothing about 1-99 in the formula, it could be anything in those cells.

Sep 24, 2020 11:57 PM in response to TechAddict

That's super helpful. I'll come back and mark it as Solved once I can get it all fathomed. As it happens there will never be two of the same number. There would only ever be something like: 1,1,2,2,3,3,4,5,6,7,8,9,9 etc, never 1,1,1,2,2,3,3,3,4,5,6,7,8,9,9,9. As there will only ever be the two, is there a straight cut and paste formula that I can insert into P6 on the original sheet but in Numbers or will it still require the minor adjustment of having the additional Column B?


I'll try and absorb it all (spreadsheet calcs aren't my thing at all LOL) and give it a go.

Sep 25, 2020 4:23 AM in response to TechAddict

If there are no missing numbers in the list (for example you will never have 1,1,3,4,etc with no 2), a simple single-cell formula should do the trick. With the all the entries in A14:A47 entered, the numbers can be in any order whatsoever as long as no number is skipped over (missing). The answer may get wonky as data is being entered if the entries are not made in numerical order, though.


=INT((MAX(A14:A47)−MIN(A14:A47)+2)÷2)


If the list always starts with 1, it can be even more simple

=INT((MAX(A14:A47)+1)÷2)

Sep 25, 2020 7:36 AM in response to TechAddict

That's absolutely awesome!! Thanks so much. The column will always start with a 1 in the first cell, the rows will always rise sequentially and there will be no missing numbers. So I pasted in the second example and it works a treat! I've copied the first just in case I find a list where I'm not 'taking' the first row entry. Thank you again for your time and immense help :) You've saved me days of work!!

Help sought with SUMPRODUCT from an Excel Sheet and displaying only rows containing data?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.