Forum Discussion

Shimi43's avatar
Shimi43
Frequent Visitor
4 years ago
Solved

Using Record.Field to pass column name variable

I'm trying to create a loop in order to create columns from sections in text and seperate the sections out from a big paragraphs.   I first did some test ones that worked perfectly (see the followi...
  • Shimi43's avatar
    Shimi43
    4 years ago

    Figured it out on my own.  Here is the code for the function in case anyone was curious.

     

    let
    fxSectionInfoGrab = (DataTable as table, PotentialSectionEnds as table) as any =>
    let
    // Turn the table into a list
    Section_List = Table.ToList(PotentialSectionEnds),

    // Determine how many ends are in the list
    TotalLoops = List.Count(Section_List),

    fxSectionInfo = (DataTableTemp, CurrentLoop) =>
    let
    // Determine Section Working on
    Section_Name = Section_List{CurrentLoop},

    // Determine Next Section Column to grab from
    Next_Section_Column = "Next Section after " & Section_List{CurrentLoop},

    // Creates TempTable to store
    tempTable = Table.AddColumn(DataTableTemp, Section_Name, each Text.BetweenDelimiters([Data], Section_Name, Record.Field(_, Next_Section_Column)), Text.Type)

    in
    // Determin the Next Section Name
    if CurrentLoop >= TotalLoops-1
    then tempTable
    else @fxSectionInfo(tempTable, CurrentLoop+1),

    //Evaluate the sub-function at the first row
    Output = fxSectionInfo(DataTable, 0)
    in
    Output
    in
    fxSectionInfoGrab