Forum Discussion

Fidzi8's avatar
Fidzi8
Helper V
1 year ago
Solved

Inserting the correct value

Hi comunnity, I need help with this problem. I have two simple tables. The first table contains a list of transports from where - to where (columns "C" - "D") on a given day (column „B“). ...
  • johnt75's avatar
    1 year ago

    You can create a calculated column in the first table like

    Distance =
    SELECTCOLUMNS (
        FILTER (
            Table2,
            Table2[ID] = Table1[ID]
                && Table2[From] = Table1[From]
                && Table2[To] = Table2[To]
                && Table2[Valid From] <= Table1[Date]
                && (
                    ISBLANK ( Table2[Valid To] )
                        || Table2[Valid To] >= Table1[Date]
                )
        ),
        "@value", Table2[Distance]
    )
    
  • johnt75's avatar
    johnt75
    1 year ago

    Try

    Distance =
    SELECTCOLUMNS (
        TOPN (
            1,
            FILTER (
                Table2,
                Table2[ID] = Table1[ID]
                    && Table2[From] = Table1[From]
                    && Table2[To] = Table2[To]
                    && (
                        ( Table2[Valid From] <= Table1[Date]
                            && Table2[Valid To] >= Table1[Date] )
                            || ( ISBLANK ( Table2[Valid To] ) && ISBLANK ( Table2[Valid From] ) )
                    )
            ),
            Table2[Value To], DESC
        ),
        "@value", Table2[Distance]
    )