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
bboy0009
Helper II
Helper II

What does this M function do ?

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 !

 

 

 

1 REPLY 1
m_dekorte
Resident Rockstar
Resident Rockstar

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

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.

Top Solution Authors