[SOLVED] Difference between two lists

Hi there

Does anyone know whether there is a function in Coda to return the difference between two lists? e.g. Difference(list(a,b,c),list(a,b,c,d,e)) would return list(d,e). Is there a way to do this with a combination of existing functions. Sorry, I’m not a programmer, so this isn’t second nature to me.

Cheers!

1 Like

List("A","B","C", "D", "E").Filter(Not(List("A", "B","C").Contains(CurrentValue))) should work.

4 Likes

Aargh, so obvious in hindsight! :flushed:

Thanks @Krunal_Sheth

I tried this, and while it worked for the small list (a,b,c,d,e), it did not work with my lists on my table.

I have two lists. One with 159 text values and one with 155 values. Im trying to locate the 4 values that are missing with the given formula, but instead of outputting those 4, it is outputting all 159 from the larger list.

Any ideas why???

If I have to guess, I would say both lists re containing values of different types. If that’s not the case please reach out to support and one us would take a look.

Thanks for reaching out. That was my guess as to what the issue was as well, but it seems as though my types are the same.

Here is a screenshot of what im currently doing. Do you see anything amiss?

The green list contains 159 names while the pink likst contains 155 names, but for some reason it is not filtering out those 4 ??

This is because List(Table) is creating a List with a single entry, where that entry is itself a list of all the values in that column of the table. You can see this by writing a formula which is List(All Students Master.Student Name) or List(All Students Master.Student Name).Count()

If you remove both the List() portion, it should work as All Students Master.Student Name.Filter(Not(Scott - IEPs.Student Name to Text).Contains(Current Value)))

Note that you could also write this as a more standard filter – All Students Master.Filter(Scott IEPs.Student Name to Test.Contains(Student Name).Not())

Does that work better?

Thank you @shishir! Everything you said makes sense, but for some reason I’m still coming up with errors.

Here is a screenshot of what is happening

Any ideas?

Ah sorry, looks like I had a typo in my suggestion. Good learning moment though - in that formula, Not() is in the wrong place. It’s testing Not(column) which is going to return true or false, and then passing that into the Contains() function. The second variation should work (All Students Master.Filter(Scott IEPs.Student Name to Test.Contains(Student Name).Not())) - it’s one of the reasons I tend to prefer dot notation, it’s easier to prevent errors.

I also wrote up a bit of step-by-step example of what each of these formulas are doing here:

4 Likes

Thank you so much! It works now!