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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
SCC1991
New Member

Did you use the [field] shorthand for a _[field] outside of an 'each' expression?

Hi guys

 

I am receiving the following error when invoking a custom function:

 

Expression.Error: There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?

 

We have the following Custom Function:

 

let
Query2 = (Vardate as text)=>
let
Source = Web.BrowserContents("https://www.xe.com/currencytables/?from=USD&date=",[RelativePath=[Vardate]]),
#"Extracted Table From Html" = Html.Table(Source, {{"Column1", "TABLE.currencytables__Table-xlq26m-3.jaGdii > * > TR > :nth-child(1)"}, {"Column2", "TABLE.currencytables__Table-xlq26m-3.jaGdii > * > TR > :nth-child(2)"}, {"Column3", "TABLE.currencytables__Table-xlq26m-3.jaGdii > * > TR > :nth-child(3)"}, {"Column4", "TABLE.currencytables__Table-xlq26m-3.jaGdii > * > TR > :nth-child(4)"}}, [RowSelector="TABLE.currencytables__Table-xlq26m-3.jaGdii > * > TR"]),
#"Promoted Headers" = Table.PromoteHeaders(#"Extracted Table From Html", [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Currency", type text}, {"Name", type text}, {"Units per USD", type number}, {"USD per unit", type number}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Currency", "Currency code#(lf)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)▲▼"}, {"Name", "Currency name#(lf)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)▲▼"}, {"USD per unit", "USD per Unit"}})
in
#"Renamed Columns"
in
Query2

 

Which is then invoked into the following Query:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W0jVSio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Offset = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Offset", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Date", each Date.ToText(Date.AddDays(Date.From(DateTime.LocalNow()),-2),"yyyy-MM-dd")),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Date", type text}}),
#"Invoked Custom Function1" = Table.AddColumn(#"Changed Type1", "currency_conversion", each #"XE Date"([Date])),
#"Expanded currency_conversion" = Table.ExpandTableColumn(#"Invoked Custom Function1", "currency_conversion", {"Currency code#(lf)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)▲▼", "Currency name#(lf)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)▲▼", "Units per USD", "USD per Unit"}, {"Currency code#(lf)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)▲▼", "Currency name#(lf)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)#(tab)▲▼", "Units per USD", "USD per Unit"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded currency_conversion",{"Offset", "Date"}),
#"Changed Type2" = Table.TransformColumnTypes(#"Removed Columns",{{"Units per USD", type number}, {"USD per Unit", type number}})
in
#"Changed Type2"

 

---

 

Would anyone be able to assist?

 

Thanks

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @SCC1991 ,

 

Try this:

 

let
Query2 = (Vardate as text)=>
let
    Source = Web.Contents("https://www.xe.com/currencytables/",[Query = [from="USD", date="2021-04-20"]]),
    #"Extracted Table From Html" = Html.Table(Source, {{"Column1", "TABLE.currencytables__Table-xlq26m-3.jaGdii > * > TR > :nth-child(1)"}, {"Column2", "TABLE.currencytables__Table-xlq26m-3.jaGdii > * > TR > :nth-child(2)"}, {"Column3", "TABLE.currencytables__Table-xlq26m-3.jaGdii > * > TR > :nth-child(3)"}, {"Column4", "TABLE.currencytables__Table-xlq26m-3.jaGdii > * > TR > :nth-child(4)"}}, [RowSelector="TABLE.currencytables__Table-xlq26m-3.jaGdii > * > TR"]),
    #"Promoted Headers" = Table.PromoteHeaders(#"Extracted Table From Html", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Currency", type text}, {"Name", type text}, {"Units per USD", type number}, {"USD per unit", type number}})
in
    #"Changed Type"
in
Query2

 

query2.gif

 

And it can set scheduled refresh.

query2 refresh.PNG

 

 

 

Best Regards,

Icey

 

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

View solution in original post

5 REPLIES 5
Icey
Community Support
Community Support

Hi @SCC1991 ,

 

Try this:

 

let
Query2 = (Vardate as text)=>
let
    Source = Web.Contents("https://www.xe.com/currencytables/",[Query = [from="USD", date="2021-04-20"]]),
    #"Extracted Table From Html" = Html.Table(Source, {{"Column1", "TABLE.currencytables__Table-xlq26m-3.jaGdii > * > TR > :nth-child(1)"}, {"Column2", "TABLE.currencytables__Table-xlq26m-3.jaGdii > * > TR > :nth-child(2)"}, {"Column3", "TABLE.currencytables__Table-xlq26m-3.jaGdii > * > TR > :nth-child(3)"}, {"Column4", "TABLE.currencytables__Table-xlq26m-3.jaGdii > * > TR > :nth-child(4)"}}, [RowSelector="TABLE.currencytables__Table-xlq26m-3.jaGdii > * > TR"]),
    #"Promoted Headers" = Table.PromoteHeaders(#"Extracted Table From Html", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Currency", type text}, {"Name", type text}, {"Units per USD", type number}, {"USD per unit", type number}})
in
    #"Changed Type"
in
Query2

 

query2.gif

 

And it can set scheduled refresh.

query2 refresh.PNG

 

 

 

Best Regards,

Icey

 

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

watkinnc
Super User
Super User

How bout:

Source = Web.BrowserContents("https://www.xe.com/currencytables/?from=USD&date="&Vardate),

 

 


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

I tried that route originally, it works yes, but it prevents Dynamic Refresh's from happening, which is why we went down the invoke custom function in the first place.

SCC1991
New Member

Hi

 

I did try this, and have tried this again now - I receive this error now:

 

DataSource.Error: Web.BrowserContents: This function doesn't support the query option 'RelativePath' with value '"2021-04-18"'.
Details:
2021-04-18

 

Thanks,

watkinnc
Super User
Super User

It's should be written in your query as [RelativePath = VarDate] (VarDate is a text variable, and doesn't need to be enclosed in [ ]
--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors