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.
Hello,
I'm looking for the basic structure for how to take a single column from a table or list and run a function with each item in the list as parameters or variable in the function. I read a post where @danextian was able to anwser 'looping in m code' for someone else and I'm trying to do something similar and get a better understanding.
I'm trying to take each row from a list of Ids and append the url with that value.
Apologies if I'm going in the wrong direction with List.Generate but it seemed possible. I don't care if I have to create a new table of results or if I have to add it as a column to an existing table, I'm fine with either as long as I can get the results and learn the proper syntax 🙂
Similar Post:
Example:
let
visa = SpecialProject,
visaWithoutQuotes = Text.Remove(visa,""""),
Auth2 = "Bearer "&visaWithoutQuotes&"",
listOfResults = List.Generate ( ()=>
JustAccounts[AccountId], //List I'm starting with
each JustAccounts[AccountId]([_]) {[Index]+1} <> null, //If the next line in the list is not empyt then run the function
each [Result = Json.Document(Web.Contents(Text.Combine("https://api/statistics/devices/id/",[_]), [Headers = [#"Authorization" = Auth2]]))] //function to run on each line
)
in
listOfResults
Thanks in advance for any help suggested 🙂
Solved! Go to Solution.
Hi @papi0506 ,
sorry, wrote if from the head. Please try the following:
Json.Document(Web.Contents("https://api/statistics/devices/id/" & [AccountId] ))
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Hi @papi0506 ,
sorry, wrote if from the head. Please try the following:
Json.Document(Web.Contents("https://api/statistics/devices/id/" & [AccountId] ))
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Thank you, your suggestion looks to have helped the call progress but the results mention that we cannnot convert a value of record type to number. I had to use text.from to help pass a previous error to the current results.
@ImkeFThank you, very much. after clearing some cache and results, I was able to get a 404, so the command is working properly I just need to work on the call and why its returning 404, not a power querie issue.
Thank you so much.
same call and worked 🙂
#"Added Custom" = Table.AddColumn(AccountListAsTable, "Results", each Json.Document(Web.Contents("https://api/statistics/devices/id/" & Text.From([IDS] as any),[Headers = [#"Authorization" = Auth2]])))
Hi @papi0506 ,
if you add a column to a table using the UI, a simple and easy loop will be performed, as every action that you define will be applied to every row of the table. No need to use List.Generate here, this function is only required if you need some recursive features.
So if you add a column with the following code, it should work in Power BI Desktop:
Json.Document(Web.Contents(Text.Combine("https://api/statistics/devices/id/" , [AccountId] )))
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Thank you for your response, but I may not be following this properly. When I try with just the line you provided it presents an error and wants the text of the url as a list?
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.