Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
jasontran
Helper I
Helper I

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 13
v-juanli-msft
Community Support
Community Support

Hi @jasontran 

I would value lbendlin's answer.

Capture5.JPG

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.

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]
)

Hi @jasontran 

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

[[ should be [.

 

Best Regards

Maggie

Still getting an error. This time it's highlighted the end close bracket of the formula

Hi @jasontran 

Is this problem sloved? 

If it is sloved, could you kindly accept it as a solution to close this case and help the other members find it more quickly?

If not, please feel free to let me know.

 

Best Regards

Maggie

Hi @jasontran 

To help you slove it, please show the code below from your query.

******
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", (x)=>Table.SelectRows(Original,each [ID]=x[ID] and [Letter Date]=x[Original Date])),
*****

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.

show the entire line of code

amitchandak
Super User
Super User

@jasontran , refer if this can help

https://eriksvensen.wordpress.com/2019/02/28/powerquery-replicate-doing-an-excel-vlookup-in-m/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

How would you nest an IF statement within this?

Nesting ifs in Power Query is very simplistic

 

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

i meant in the context of utilizing a lookup. that doesnt seem possible with the need to create a function in a separate query for a lookup

yes, you can use that inside the function without issues.

 

Here's an example

 

#"Added Custom" = Table.AddColumn(Index, "Match", 
        (k) => Table.SelectRows(#"Assignments",
            each ([AID]="*" or k[AID]=[AID])
                and ([PSA]="*" or k[PSA]=[PSA])
                and ([SID]="*" or k[SID]=[SID])
                )
            ),
lbendlin
Super User
Super User

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.