Forum Discussion

KasperJ90's avatar
KasperJ90
Helper III
3 years ago
Solved

Power Query code for lookup value in a range in another table and return text from that table

Hi all,   I have a tabel with a range of "Minute Type". I want to add the "Minute Type" to each line in tabel Prod Line based on the No_ as a calculated column: Tabel Range     Tabel Prod...
  • v-yanjiang-msft's avatar
    3 years ago

    Hi KasperJ90 ,

    According to your description, here's my solution.

    1. Power Query.

    Add a custom column in Prod Line table.

    Table.SelectRows(Range,(x)=> x[Operation From]<=[No_] and x[Operation To] >=[No_])[Minute Type]

    Then expand the column, get the correct result.

    2. DAX

    Create a calculated column in Prod Line table.

    Column =
    MAXX (
        FILTER (
            'Range',
            'Range'[Operation From] <= EARLIER ( 'Prod Line'[No_] )
                && 'Range'[Operation To] >= EARLIER ( 'Prod Line'[No_] )
        ),
        'Range'[Minute Type]
    )
    

    Get the correct result.

    I attach my sample below for your reference.

     

    Best Regards,
    Community Support Team _ kalyj

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.