The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hi guys,
As mentionned in the title, I would like to understand what this function below does
let
Yesterday = "/received_payments_report_"&
Date.ToText( DateTime.Date( Date.AddDays(DateTime.LocalNow(), -1)) , "yyyy_MM_dd")&".csv",
getUserData = (loops as number, optional data_list as list ) =>
let
Query = Web.Contents(
"https://URL of the data source/", [RelativePath= Record.Field(_MerchantAccountHelper{loops}, "Merchant Account Name") & Yesterday]
),
Results = {Csv.Document(Query, [Delimiter = ",", Columns = 88, QuoteStyle = QuoteStyle.None])},
currentLoop = loops + 1,
currentResults =
if data_list is null then Results
else List.Combine({data_list, Results}) ,
output =
if loops > Table.RowCount(_MerchantAccountHelper) then currentResults
else @getUserData(currentLoop, currentResults )
in
output
in
getUserData
How the value of currentLoop and currentResults have been initiated ? I'm curious about it because I don't see something like currentLoop = 0 and loops doesn't also have a value. Same thing for currentResults.
Why is there an IF loop > Table.RowCount.... ?
Thank you in advance !
Hi @bboy0009
This query returns a function (value) that is designed to fetch CSV reports from a web source. getUserData has two parameters to fetch data, loops as number, and optionally appends it's restult to a list of data, optional data_list as list, That answers your fist question, the value of loop in currentLoop is determined by the user's first argument value when this function is invoked.
The if loops > Table.RowCount determines whether to continue looping or to return the final results. If the loop counter exceeds the number of merchant accounts, it returns the currentResults, ending the looping process. Otherwise, it recursively calls getUserData incrementing the loop counter +1, continuing the looping process to fetch and combine a new set of results to the previous ones.
I hope this is helpful