[Solved] Function to test if 2 ranges are element-wise equal

Discuss the spreadsheet application
Post Reply
smjg
Posts: 4
Joined: Sun Sep 05, 2010 1:03 am

[Solved] Function to test if 2 ranges are element-wise equal

Post by smjg »

Hello,

Using OpenOffice 4.1.5, Windows 10.

It ought to be possible to write a formula to compare two ranges and test whether they contain the same values, without having to list them individually.

In other words, something like

Code: Select all

=EQUAL(A1:A4;B1:B4)
which would be equivalent to

Code: Select all

=AND(A1=B1;A2=B2;A3=B3;A4=B4)
but the ranges could potentially be much bigger than this, such that listing all the pairs of cells to compare would be too cumbersome.

Can anyone advise?

Thanks
Last edited by smjg on Wed Jul 31, 2019 1:53 am, edited 1 time in total.
OpenOffice 4.1.5 on Windows 10
FJCC
Moderator
Posts: 9279
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Function to test whether two ranges are element-wise equ

Post by FJCC »

This formula will tell you how many pairs in A1:A4 vs B1:B4 are unequal, so a value of zero means they are all equal.

Code: Select all

=SUMPRODUCT(A1:A4 <> B1:B4)
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
MrProgrammer
Moderator
Posts: 4908
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Function to test whether two ranges are element-wise equ

Post by MrProgrammer »

smjg wrote:It ought to be possible to write a formula to compare two ranges and test whether they contain the same values, without having to list them individually.
Type =AND(X2:X999=Y2:Y999) and press ⇪⌘Enter (Shift+Command+Enter) on a Mac or Ctrl+Shift+Enter on other platforms; if you press Enter by mistake, use Edit → Delete contents → Formulas, then try again.

If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the title. You can select the green checkmark icon at the same time.

[Tutorial] Ten concepts that every Calc user should know
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
smjg
Posts: 4
Joined: Sun Sep 05, 2010 1:03 am

Re: Function to test whether two ranges are element-wise equ

Post by smjg »

Thanks both. I hadn't got my head around how array formulae work in OpenOffice. I'd wondered why SUMPRODUCT works but neither SUM nor PRODUCT does, but then discovered that SUMPRODUCT is the only one of the three that has "forced array handling".
OpenOffice 4.1.5 on Windows 10
User avatar
RusselB
Moderator
Posts: 6646
Joined: Fri Jan 03, 2014 7:31 am
Location: Sarnia, ON

Re: [Solved]Function to test if 2 ranges are element-wise eq

Post by RusselB »

Please note that for any of the responses, the range sizes must be the same... X columns and Y rows

Off topic, please go to the User Control Panel and update your forum signature.
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
Post Reply