Understaing expressions

Hi,
Need help to write a really simple script that remove a underscore if its alone like “"
In total it adds up “name1” + "
” + “name2” + “_” “name3” so that would be name1_name2_name3
but if one of the fields is empty it should not return underscores like name2 but just name2 or
just name1_name3 etc.

I’m a newbie and figured it out on airtable with the help of chatgpt but chatgpt dont understand baserow so i’m out of luck.

Thanks :slight_smile:

Not an easy one, but I think you can fix this with the following formula

concat(field('Title'),if(or(field('Title') = '',field('Subtitle') = ''),'','_'),field('Subtitle'),if(and(field('Subtitle') = '',field('Description') = ''),'','_'),field('Description'))

In plain english: concatenate the following fields:

  • Always start with the value of the field Title
  • check if the field Title or the field Subtitle have text in them. If yes: add the underscore, otherwise add an empty string
  • Always add the value of the field Subtitle
  • Check if the field Subtitle and the field Description both have a value. If yes: add the underscore, otherwise an empty string
  • Always add the value of the field Description

I used the following table structure and values to test the formula

Regards
Frederik

Thanks thats exatcly it. Thanks!

Any idea how to train Chatgpt to help people like me?

Chat gpts solution on airtable:
& IF({{ Title }}, “" & {{ Title }}, “”)
& IF({{ Subtitle }}, "
” & {{ Subtitle }}, “”)

But that doesn’t translate to baserow.
Is baserow and airtable expressions based on different launguages?
Sorry for all the newbie questions :slight_smile:

Hi,

I am not an expert in AI or ChatGPT, so I cannot help you with that. Baserow uses it own formula language:
From: Baserow Formula Technical Guide // Baserow

Baserow formulas are written in the open source Baserow Formula language which is a simple expression based language similar to formulas you will find in other spreadsheet tools.

In other words, it works similar to Airtable, Google Sheets or MS Excel formulas, but it has its own syntax.

I check your question again, and I think the easiest way to solve it is to divide your “problem” into smaller portions. In the screenshot below, the field ‘Remove right’ holds the final value. You can hide all the other fields. The test data ensures that all scenarios are tested.

  • Field 1 (Concat): Concatenate all fields with an underscore: concat(field('Title'),'_',field('Subtitle'),'_',field('Description'))
  • Field 2 (Regex): check for double underscores and replace them with a single one: regex_replace(field('Concat'), "__", "_")
  • Field 3 (Remove left): check if the first character is an underscore, and remove it if true: if(left(field('Regex'),1) = '_', right(field('Regex'), length(field('Regex')) - 1), field('Regex'))
  • Field 4 (Remove right): check if the last character is an underscore and remove it if true: if(right(field('Remove left'),1) = '_', left(field('Remove left'), length(field('Remove left')) - 1), field('Remove left'))

You can now hide (but not remove) fields 1 - 3. You can nest formulas if you want less columns, but dividing a problem into partial problems keeps your formulas more readable and easer to understand if you need to change them later.

Regards
Frederik