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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

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
Super User
Super User

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors