Notion Answers

Help between Notion users


Register & Ask

It's free & easy

Get answers

Answers, votes & comments

Vote and select answers

Receive points, vote and give the solution

Question

1vote

I have a global tags database; within that database, I have the properties: "Tag Name"- title property, "Parent Tag"- Relation to this database, "Sub-Tag"- Relation to this database, "Description"- Text property, "Sub-tags Count"- Formula property, "Unformatted Sub-tags Count"- Rollup, then I have relations to my Documents, Notes, and Notebooks databases. I am looking for a formula that will auto-generate the full path of each tag, with its complete hierarchical path, into a formula property called "Full Path (Auto). Example: For a child tag "Nutrition" under "Health," which is under "Areas of Life," the Full Path would be "Areas of Life/Health/Nutrition." This way, when tagging an item in another database, I can search the relation property by any part of the tag's path; if I search the parent tag name, it will show all its child tags. Can anyone help me out with a formula to do this?

2 Answers

0vote

polle Points100650

Without seeing the complete structure is difficult to tell, but you can try calling the properties and formatting them to text with something like this.

"Areas of " + format(prop("One")+"/"+prop("Two")+"/"+prop("Three"))

That Notion formula is just calling and formatting to text the properties One, Two and Three + the needed text.

You will need to adjust it to your properties names and extend it with some "if" scenarios where there is nothing in the property.

Hope that helps.

0vote

Mobayad Points140

Hey there! I've been training my own AI model on all the Notion formula information available on the internet and it suggested this answer to your formula puzzle.

If you're interested in trying it out yourself, please let me know.

Model Reply Below:

I'll help you create a formula for generating the full hierarchical path of tags in Notion. Let's solve this step by step.

First, we need to consider that:

  1. We need to get the parent tag's name recursively
  2. We need to handle cases where there might be no parent tag
  3. We want to join the path components with "/"
  4. We need to handle potential empty states

Here's the formula solution:

/* First get parent tag info if it exists */
let(
    parent_path,
    if(
        empty(prop("Parent Tag")),
        "",
        prop("Parent Tag").map(current["Tag Name"]).join("")
    ),

    /* Then combine with current tag name */
    if(
        empty(parent_path),
        prop("Tag Name"),  /* If no parent, just use current tag name */
        parent_path + "/" + prop("Tag Name")  /* Otherwise join with slash */
    )
)

Let's break down how this works:

  1. We use let() to store the parent path calculation for clarity and efficiency

  2. For the parent path:

    • Check if there's a parent tag using empty(prop("Parent Tag"))
    • If no parent, return empty string
    • If there is a parent, get its Tag Name using prop("Parent Tag").map(current["Tag Name"])
    • The .join("") combines in case there are multiple parents (though typically there should be only one)
  3. For the final combination:
    • If parent_path is empty, just return the current tag's name
    • Otherwise, combine parent_path + "/" + current tag name

This will generate paths like:

  • "Areas of Life/Health/Nutrition"
  • "Areas of Life/Health"
  • "Areas of Life"

Some important notes:

  1. Make sure your property names match exactly:

    • "Tag Name" for the title property
    • "Parent Tag" for the relation property
  2. This formula assumes a single parent per tag. If you have multiple parents, you might want to modify the formula to handle that case.

  3. You should create this as a Formula property named "Full Path (Auto)"

If you want to make it even more robust, here's an enhanced version that handles more edge cases:

/* Enhanced version with better error handling */
let(
    parent_path,
    if(
        empty(prop("Parent Tag")),
        "",
        prop("Parent Tag")
            .filter(!empty(current["Tag Name"]))  /* Filter out any empty names */
            .map(current["Tag Name"])
            .join("/")  /* Join multiple parents with slash if they exist */
    ),

    /* Combine with current tag name, handling empty current tag case */
    if(
        empty(prop("Tag Name")),
        "Unnamed Tag",  /* Default value for empty tags */
        if(
            empty(parent_path),
            prop("Tag Name"),
            parent_path + "/" + prop("Tag Name")
        )
    )
)

This enhanced version:

  1. Filters out any empty tag names in the parent chain
  2. Handles the case where the current tag name might be empty
  3. Uses a more robust joining strategy for multiple parents (if they exist)

You can then use this "Full Path (Auto)" property in your relations to other databases, and as you mentioned, searching for any part of the path will help you find the relevant tags.

For optimal performance, ensure that:

  1. Your parent-child relationships don't create circular references
  2. Tags have unique names within their hierarchical level
  3. The Parent Tag relation is properly maintained

Please log in or register to answer this question.

...

Welcome to Notion Answers, where you can ask questions and receive answers from other members of the community.

Please share to grow the Notion Community!

Connect