Hoping someone might be able to help with this. I’m trying to fetch a list using Dataview from a multi-value field across multiple files. This is an example of what the files look like:
- category 1
- category 2
- category 3
Currently when I do the following I get all the categories but since multiple files can have multiple categories there are lots of duplicates which I’m trying to avoid. Basically looking to make a similar view to the Tags pane but for custom values.
group by categories
How do you mark your categories? Or put another way, how do you distinguish between normal list items and your category list items?
Do you have an example on how to gather your categories (even if they contain duplicates)?
Everything is in the frontmatter before hand where the categories are also listed just like I shared above. I’m basically using Obsidian like a simple CMS for my Hugo blog and I’m using both tags and categories to distinguish posts on the site. I’d like a list of the categories similar to the tags pane so I can sort my posts correctly. Here’s a screenshot of what I get currently with just listing categories, this is showing 3 posts.
I’ve added a few to the posts to show the duplicates but I do have multiple posts under the same category and I’d basically just like to see the category listed once.
Thanks for the sample data, which makes it a lot easier to help you. In your query you’re actually grouping on the list of categories, so you would only “remove” duplicated lists, and not duplicated singular categories.
To handle each category on its own you need to split up the lists, by doing something like
FLATTEN categories as category, and then
GROUP BY category. This results in the following query:
FLATTEN categories as category
GROUP BY category
In my test setup, that simplifies all the various definitions of categories into a single list of the unique values.
flatten is much more powerful then I imagined. In my head I just saw it as a way to separate values. Thanks for the help this works perfectly
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.