How Do I Omit Items in an Array from a List

What I’m trying to do

I’m wanting to generate a list of all existing lectures that omits the ones listed in the “compLectures” array.

Things I have tried

I have a collection of files tagged with “#lecture”.
I have a student file with the variable “compLectures” that is an array with the names of the lectures the student has completed.
Each lecture has a variable “rank” labeled from “F” to “A” to symbolize progression.

For this example, the array is set as:

compLectures: 
 - Care for Materials
 - How to See

I have tried with the above as “[[Care for Materials]]” also, but that didn’t work, and it made the “Completed” section have to be written differently.

This is what I’ve tried. Well, I’ve tried many things, but nothing I’ve tried has worked.
image

This gives me:
image

As you can see, it did not omit the two listed in the array. This did work when there was only a single item in the array, but that doesn’t work for my purposes.

I have tried !contains (since everything is spelled exactly), !icontains, and !econtains. I have not gotten the results I’m looking for.

I have tried FLATTEN with compLectures, but that doesn’t omit the files and also makes duplicates of everything in the output.

As I understand,

In the contains function family you may iterate on the elements of a list as long as the list is the first parameter passed to the function.

Unfortunately, in your code , the first parameter passed to icontains is a string.

Try (grouping skipped) to reverse the logic:

LIST
FROM #Lecture
WHERE !icontains(this.compLectures, row.file.name)
1 Like

Are you saying that each lecture only has one rank to symbolise progression? Doesn’t that severly limit the usefullness of your queries? Or are you only using this for one student (possibly yourself)?

So with the given caveat that I don’t fully understand your setup, does either of the following queries do what you want them to?

```dataview
LIST rows.file.link
FROM #lecture
WHERE !contains(this.compLectures, file.name)
GROUP BY rank as Rank
SORT file.name ASC
SORT Rank DESC
```

## Completed
```dataview
LIST rank
FROM #lecture
WHERE contains(this.compLectures, file.name)
SORT file.name ASC
SORT rank DESC
```
1 Like

Yes, this worked. Thank you very much, I never thought of reversing it.

Changing this line did the trick.

WHERE !icontains(this.compLectures, row.file.name)

In my use case, the student is given a rank, not to identify their quality, but to identify their range of completion (progression). In order to take the lecture they must meet the criteria. There are generally 2 lectures and 2 projects per rank. So, if a lecture is rank C, they must have completed the lectures and projects from the previous ranks in order to attend. Ranks reach from E to A, with one lecture listed as “F” because “introductory” isn’t a letter.

Also, thank you for that code. The Completed section wasn’t looking how I wanted, and with this, it now is.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.