Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

DAX > M Query - LOOKUPVALUE

Any tips on how to convert this DAX over to M?

 

The below displays as expected but I need the transformation to occur in Power Query to conduct subsequent steps on the existing [From Date] and generated [New To Date]


New To Date = SWITCH( TRUE(),
Recall[Type]="Recall" && Recall[Flag]<>BLANK(),
LOOKUPVALUE(Original[To Date],
Original[Letter Date],Recall[Original Date],
Original[ID],Recall[ID],
BLANK()
),
BLANK()

)

 

Sample data as follows

[Original]

IDTypeLetter DateOriginal DateFrom DateTo DateFlag
AOrder29-Apr-2017-Apr-2013-Apr-2031-May-20Yes
ARecall28-May29-Apr-2025-May-20 Yes
BOrder11-May-20 26-May-2023-Jun-20Yes
BRecall09-Jun-2011-May-2017-Jun-20 Yes

 

[Recall]

IDTypeLetter DateOriginal DateFrom DateTo DateFlagNew To Date
ARecall28-May-2029-Apr-2025-May-20 Yes31-May-20
BRecall09-Jun-2011-May-2017-Jun-20 Yes21-Jun-20

 

13 Replies

  • use Table.AddColumn() with a custom function as column generator. Inside the function you can apply the lookup to your reference table.

    • Anonymous's avatar
      Anonymous
      Not applicable

      How would you nest an IF statement within this?

      • lbendlin's avatar
        lbendlin
        Icon for Super User rankSuper User

        Nesting ifs in Power Query is very simplistic

         

        if this then that else if this1 then that1 else if this2 then that2 else this3

  • v-juanli-msft's avatar
    v-juanli-msft
    Icon for Community Support rankCommunity Support

    Hi Anonymous 

    I would value lbendlin's answer.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUQpKTU7MyQEyjCx0fRMrdY0MQGxLXceCIijbFCEORJGpxUqxOtFKTsh6LXW9SvMgSgwNEcoNzRHiMK2xAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Type = _t, #"Letter Date" = _t, #"Original Date" = _t, #"From Date" = _t, #"To Date" = _t, Flag = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Type", type text}, {"Letter Date", type date}, {"Original Date", type date}, {"From Date", type date}, {"To Date", type text}, {"Flag", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", (x)=>Table.SelectRows(Original,
                each [ID]=x[ID] and [Letter Date]=x[Original Date])),
        #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"To Date"}, {"Custom.To Date"})
    in
        #"Expanded Custom"

     

    Best Regards
    Maggie
    Community Support Team _ Maggie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Anonymous's avatar
      Anonymous
      Not applicable

      I've tried to apply the logic via a Custom Column but am getting a "Token Comma expected" error.

       

      (x) => Table.SelectRows(#"FV-ToDt",
      each [Employee ID] = x[[Employee ID]
      and [To Date]=x[From Date]
      )

      • v-juanli-msft's avatar
        v-juanli-msft
        Icon for Community Support rankCommunity Support

        Hi Anonymous 

        (x) => Table.SelectRows(#"FV-ToDt",
        each [Employee ID] = x[[Employee ID]
        and [To Date]=x[From Date]
        )

        [[ should be [.

         

        Best Regards

        Maggie