OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

regexp string comparison in array functions

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc
View previous topic :: View next topic  
Author Message
Cazaril
General User
General User


Joined: 09 Jun 2003
Posts: 16

PostPosted: Sun Nov 25, 2007 4:23 pm    Post subject: regexp string comparison in array functions Reply with quote

Hi,

I have this little problem evaluating a table. The format of the table is basically like this:

val1 phone1 time1
val2 phone2 time2
...

I'd like to add all times, if VALx=="something" and PHONEx="1.*". Meaning: If the VALx is a certain value I know, and the phone number starts with one. I have developed the following little array formula:

==SUM((I2:I200="IWE")*(H2:H200="1.*")*((J2:J200)/86400))

Alas, it does not work. the string comparison in the 2nd part is always false, as I have found out. does anyone know how I can solve this thing? I break my head since 2 hours at least, in which I could have the whole thing done by hand several times Smile , but I'd like to know why this fails ... . the screenshot below should illustrate the problem.



I am using neoffice newest 2.2.2 patch 2 for mac os btw., and yes, I did enable "regular expressions in formulas" in the OO options Wink


thanks in advance for any responses!
Back to top
View user's profile Send private message
acknak
Moderator
Moderator


Joined: 13 Aug 2004
Posts: 4295
Location: ~ 40°N,75°W

PostPosted: Sun Nov 25, 2007 6:24 pm    Post subject: Reply with quote

Unfortunately, only a few special places will use regular expression matching, and plain string comparison ('=') is not one of them.

This works for me:
Code:
{=SUM( IF(
      ISERR( SEARCH(".*IWE.*"; A1:A2));
       0; B1:B2))}

As does this:
Code:
{=SUM( IF(
      ISERR( SEARCH("^1.*"; B1:B2));
       0; B1:B2))}

but this doesn't
Code:
{=SUM( IF( OR(
      ISERR( SEARCH(".*IWE.*"; A1:A2));
      ISERR( SEARCH("^1.*"; B1:B2)));
       0; B1:B2))}

I can't figure out why that won't work, or find a way around it:
Back to top
View user's profile Send private message
drking
Power User
Power User


Joined: 25 Oct 2006
Posts: 91

PostPosted: Tue Nov 27, 2007 5:38 am    Post subject: Reply with quote

I've had a look at using countif, which is another way to test simple comparisons with regex

=COUNTIF(B1; "^1.*" ) returns 1 or 0

Unfortunately in an array the B1:B2 is interpreted by COUNTIF, not the array processing [eg =SUMPRODUCT(COUNTIF(B1:B2; "^1.*" ); ..........) ]

Looking at search:
=SEARCH("^1.*"; B1:B2)
is (rightly or wrongly) a valid syntax, but only cell B1 will be searched. So once you stick it in an array, I wonder if under certain conditions SEARCH is interpreting the B1:B2, rather than the array processing. That might explain why your example doesn't work.

I'm sorry I haven't found a full solution yet either.
Back to top
View user's profile Send private message
drking
Power User
Power User


Joined: 25 Oct 2006
Posts: 91

PostPosted: Tue Nov 27, 2007 5:51 am    Post subject: Reply with quote

aha!

=SUMPRODUCT((I2:I200="IWE");NOT(ISERR(SEARCH("^1.*";H2:H200)));(J2:J200)/86400)

(assuming the first term doesn't use regex)
Back to top
View user's profile Send private message
Cazaril
General User
General User


Joined: 09 Jun 2003
Posts: 16

PostPosted: Tue Nov 27, 2007 5:53 am    Post subject: Reply with quote

The solution from drking with if(iserr(search(...))) does work for me, as far as I have tested. It's a shame though that the "=" operator does not support regex in this context - it's a very powerful method of evaluating data, and this makes things un-intuitive and unneccessarily hard.

Thanks for your efforts, though!! Smile

Would this be an item for a feature request - what do you think?
Back to top
View user's profile Send private message
acknak
Moderator
Moderator


Joined: 13 Aug 2004
Posts: 4295
Location: ~ 40°N,75°W

PostPosted: Tue Nov 27, 2007 6:05 am    Post subject: Reply with quote

Sure, it should be an option for any string comparison.

You can file a request here: Open Office Quality Assurance - Report Bugs

Just be sure to do a search first--someone may have already asked for it.
Back to top
View user's profile Send private message
drking
Power User
Power User


Joined: 25 Oct 2006
Posts: 91

PostPosted: Tue Nov 27, 2007 6:28 am    Post subject: Reply with quote

I've recently trawled through almost 40 regex issues in order to write the regex HowTos, and I don't recall this feature being on the list of enhancement requests
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group