Group by with choice for mix of local and online images

What I’m trying to do

I have been documenting my movie and tv libraries in obsidian. I have a query that shows all my movies and it works great - I’m able to show the local/sync image of movies I own physically and an API linked image to movies I own digitally. I use a choice formula to do this.

For my tv shows, I want to do the same thing but I want to group them by the name of the show. I’ve gotten the local/sync photos to work, but the choice seems to be failing on rows that I own digitally. The choice result is as if it is a physical copy and not a digital copyc so the image isn’t displaying in the results. I’ve tried several combinations of where I put the word rows and nothing seems to fix it. The other choice formula I have for the location is working perfectly, but mimicking that logic doesn’t seem to be working for the images. Yet this image choice formula works fine without grouping and rows. There is a possibility that I could even have some seasons of a show physically and some digitally so I’d really like to get this to work.

Any ideas what I’m doing wrong? I’m pretty new to Obsidian and dataview and haven’t tried dataviewjs, I’d like this to work without using js if at all possible because I’m not ready to learn that haha.

Here is my query:


showname AS "Show",

choice(bldg = "digital",rows.image,embed(link(rows.image, "50"))) AS "Pic",

choice(bldg = "digital",rows.firstcontainer,rows.bldg) AS "Location",

rows.seasons AS "S",

rows.episodes AS "E"

FROM "Storage/TV Shows"

Group by showname

SORT showname Asc

Here is a screenshot of what the images are doing.

Here is a screenshot of the local images working perfectly for a show with multiple records/images

Here are the properties on the 30 Rock record in the screenshot that I’m using in the query. I’m putting it in a code block here just so you can see the image format (it was trying to display the image itself in this post), but it isn’t in a code block in the file. I find it easier to edit my properties using the format of [name:: value] so that’s why they’re like this.

[bldg:: digital]

[firstcontainer:: example]

[image:: "![image|50]("]

[seasons:: 1-2]

[episodes:: All]

[showname:: 30 Rock]

The difference for physical copies is that the image property looks like this because the file is local (example from the screenshot):

[image:: “adventuretimeseason01image.jpg”]

Here is one more example of the choice formula for images working perfectly on my movie library where I don’t use any grouping.

Things I have tried

I searched the help docs and forum and discord for obsidian dataview group by choice, images, and rows.

I tried adding “rows.” at various places in the choice formula. I tried adjusting the front matter of the image property for files with linked API images.

Are you sure your query is actually giving any positive response on your choices, or is it always displaying the negative response?

The reason I’m asking is that after the GROUP BY all fields are collated into the rows object. Which indicates that doing a choice( bldg = "...", ... , ...) should always fail since there isn’t any bldg field anymore. Just the rows.bldg field list.

And it would also be nice to see more entries displaying cases that doesn’t work as expected alongside with some you consider working.

1 Like

You described it better than me :smile: - that is exactly what I think it’s doing; always displaying the negative response.

Now that you mention it though and I looked more closely, it looks like my other choice isn’t working either (the one that doesn’t make a choice between two images). :frowning: So it seems like none of my choices are finding a match on the bldg property probably for the reason you described.

Do you know how I can fix it? I did try it with rows on the first part of the choice like this, but that didn’t change anything:
choice(rows.bldg = “digital”,rows.image,embed(link(rows.image, “50”))) AS “Pic”

Here are several more rows that are showing the negative response.

I don’t have any examples that are showing the positive response with the group by.

You could try the following:

map(rows, (r) => choice(r.bldg = "digital", r.image, embed(link(r.image, "50")))) as Pic

Untested but the concept is sound and works. This maps each entry according to your choice.

1 Like

It worked!! I hadn’t learned about the map function yet, another one for me to do more reading on so I understand it better.

I even tested it on one where I have some digital and some physical seasons of the same show and it’s perfect! :tada:

Thank you so much for your help!

1 Like

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