Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I filter zeros from a dynamically generated array in Excel?

I'm trying to generate a list of all the factors of a number in MS Excel. I have the following formula:

=NOT(MOD(12,SEQUENCE(1,12)))*(SEQUENCE(1,12))

This gives me an array with factors and zeros, as below:

1 2 3 4 0 6 0 0 0 0 0 12

But I can't seem to find a formula to remove the zeros. I've tried different permutations of LET, LAMBDA, LARGE, FILTER, SORT, and others. Nothing works. Any tips on what I could be doing wrong? I want to do this without VBA.

like image 794
Delano Mighty Avatar asked Dec 21 '25 13:12

Delano Mighty


2 Answers

This lists numbers from 1 to 12, checks which divide 12 evenly, and filters out the rest. The formula repeats the expression to test which of those numbers are not zero; that’s how FILTER() knows which entries to include in the final list. Will work in your scenario.


=FILTER(NOT(MOD(12,SEQUENCE(1,12)))*SEQUENCE(1,12),(NOT(MOD(12,SEQUENCE(1,12)))*SEQUENCE(1,12))<>0)
like image 122
cgwoz Avatar answered Dec 24 '25 04:12

cgwoz


filter() will work, but you will have to enter your formula twice:

=FILTER(NOT(MOD(12,SEQUENCE(1,12)))*(SEQUENCE(1,12)),NOT(MOD(12,SEQUENCE(1,12)))*(SEQUENCE(1,12))<>0)
like image 26
the-mad-statter Avatar answered Dec 24 '25 06:12

the-mad-statter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!