Tabelle nach Daten aus anderer Tabelle filtern?

Hallo,

mein Plan ist, in einer Tabelle mit nur einer Zeile das aktuelle (Geschäfts)Jahr über eine Einfachauswahl festzulegen. Nach diesem Eintrag möchte ich einige andere Tabllen Filtern.
Ist das möglich?

Vielen Dank

Hello @SebastianK, and welcome to the SeaTable forum!

Here’s the best solution I can offer for this case, but unfortunately it’s a bit complicated…

For each of the other tables you want to filter, you’ll need to add a link column (for example, “Reference Year”), linking to your table containing the date. You’ll then need to link each row of all the relevant tables to this single row (you can do this for a single row per table and then copy/paste the cell).

Next, in each of the relevant tables, create a second formula column (for example, “Filter by Year”) with the following formula: year({Date}) = int({Reference Year})
Note that Date must be the name of the column containing the actual date of your entries for each table, and Reference Year must be the name of your link column.
Using this formula, you compare the year of each entry in your tables to be filtered with your reference year.
Then, for each table, you can create a filter to display only the records where the result of the Filter by Year column is true.

I hope this helps!

Benjamin


Automatic German translation

Hallo und herzlich willkommen im SeaTable-Forum!

Hier ist mein bester Vorschlag für diesen Fall, aber leider ist er etwas kompliziert…

Für jede der anderen Tabellen, die Sie filtern möchten, müssen Sie eine Spalte (z. B. „Referenzjahr“) vom Typ „Verknüpfung zu anderen Einträgen“ zu Ihrer Tabelle hinzufügen, die das Datum enthält. Anschließend müssen Sie jede Zeile aller betroffenen Tabellen mit dieser einzigen Zeile verknüpfen (Sie können dies für eine einzige Zeile pro Tabelle tun und dann die Zelle kopieren und einfügen).

Anschließend erstellen Sie in jeder der betroffenen Tabellen eine zweite Spalte (z. B. „Filterung nach Jahr“) vom Typ „Formel“ mit der folgenden Formel: year({Datum}) = int({Referenzjahr})
Beachten Sie, dass Datum der Name der Spalte sein muss, die das tatsächliche Datum Ihrer Eingaben für jede Tabelle enthält, und Referenzjahr der Name Ihrer Verknüpfungsspalte.
Mit dieser Formel vergleichen Sie das Jahr jedes Datensatzes in Ihren zu filternden Tabellen mit Ihrem Referenzjahr.
Anschließend können Sie für jede Tabelle einen Filter erstellen, um nur die Datensätze anzuzeigen, bei denen das Ergebnis der Spalte Filterung nach Jahr true ist.

Ich hoffe, das hilft Ihnen weiter!

Benjamin

Vielen Dank.

Das läuft wunderbar.
Gibt es auch die Möglichkeit bei neuen Zeilen diese Verknüpfung im Feld “Referenzjahr“ automatisch zu setzen. Ich habe es mit Regeln probiert aber keine Lösung gefunden.

Vielen Dank

Hello again @SebastianK,
It is quite possible to use an automation rule to update this link for new lines. To limit the number of automation runs, I advise you to use a periodically triggered rule. To update a link like this, you will need a Python script. Here is a script that can meet this need:

from seatable_api import Base, context

base = Base(context.api_token, context.server_url)
base.auth()
reference_year_table_name = 'Table1'
reference_year_column_name = '(Geschäfts)Jahr'
reference_year_id = 'N0xYBCeFTV2OOR2jGOyv0w'

for table in [t for t in base.list_tables() if any(col.get('name') == reference_year_column_name and col.get('type') == 'link' for col in t['columns'])]:
  unreferenced_rows = base.query(f'select _id from `{table['name']}` where `{reference_year_column_name}` is null')
  if unreferenced_rows:
    try:
      res = base.batch_update_links(
        base.get_column_link_id(table['name'],reference_year_column_name), 
        table['name'], 
        reference_year_table_name, 
        [item['_id'] for item in unreferenced_rows],
        {item['_id']: [reference_year_id] for item in unreferenced_rows}
      )
      if 'success' in res and res['success']:
        print(f'Table {table['name']}: successfuly linked {len(unreferenced_rows)} row(s)')
    except Exception as e :
      print(f"Error: exception {e}")
  else:
    print(f'Table {table['name']}: no rows to update')
print('Script successfully completed')

Please note that you will need to update the contents of the variables reference_year_table_name, reference_year_column_name and reference_year_id at the beginning of the script depending on your data. To get the _id of the reference line, you can temporarily create in this table a new formula-type column with rowID() as formula.


Automatic German translation

Hallo nochmal @SebastianK,
Es ist durchaus möglich, diesen Verknüpfungen mithilfe einer Automatisierungsregel für neue Zeilen zu aktualisieren. Um die Anzahl der Automatisierungsläufe zu begrenzen, empfehle ich dir, eine regelmäßig ausgelöste Regel zu verwenden. Um einen solchen Link zu aktualisieren, benötigst du ein Python-Skript. Hier ist ein Skript, das diesen Zweck erfüllt:

Bitte beachten Sie, dass Sie den Inhalt der Variablen reference_year_table_name, reference_year_column_name und reference_year_id am Anfang des Skripts entsprechend Ihren Daten anpassen müssen. Um die _id der Referenzzeile zu erhalten, können Sie in dieser Tabelle vorübergehend eine neue Spalte vom Typ „Formel“ mit der Formel rowID() anlegen.