Forum Discussion
trying to use a query step with a function as a stand-alone
Hi monojchakrab
It looks like the issue might be that in the standalone function, the TargetTable[Ingredient] is returning a list of values, while in the original script it is returning a single value.
You can try changing the Text.Contains function to List.Contains to check if the Ingredient value is present in the list instead of a single value.
Try modifying the RateAnotherWay function as follows:
let
RateAnotherWay = (TargetTable as table )=>
Table.SelectRows(RateMaster,
(SourceTable)=>
List.Contains(TargetTable[Ingredient],SourceTable[Ingredient]))
in
RateAnotherWay
Another thing you can try is to get the first element of the list using List.First before passing it to the Text.Contains function.
let
RateAnotherWay = (TargetTable as table )=>
Table.SelectRows(RateMaster,
(SourceTable)=>
Text.Contains(List.First(TargetTable[Ingredient]),SourceTable[Ingredient]))
in
RateAnotherWay
It's also possible that the column Ingredient in the TargetTable is not a single value column, and it could be a list. In that case, you should first try to extract the single value from the list using the List.First function before using it in the Text.Contains function.
Please let me know if this works for you or if you have any other questions.
nitishsh91 - Thanks for the quick revert.
I tried both the solutions :
#1 : returns just the RateMaster table
#2 : just returns the 1st item from the list :
The Ratemaster table looks like this :
And solution 2, returns this as the result of the invoked function :
This is probably the expected behaviour - but I am not sure how do I run this function to add a column in the TargetTable, holding a table with each of these records, whereever the TargetTable[Ingredient] matches SouceTable[Ingredient]?
When I ran this from within the script - this is what I was getting :
Then I expanded the table and simply kep the Price column in the expanded table step.
Is there a way to do the exact same with the fucntion now sitting outside the query script?
Thanks