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

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.

Reply
MP_123
Employee
Employee

Iterate over each cell in a table

hi,

i want to iterate on each cell in the column (don't know how many rows and column will be, but it's not complicated to get)

i want to call a function from each cell, how can i do it?

also possible to call this function on specific row (not column)

 

this is the function that i found here once

let

/* Function code from http://markvsql.com/2015/03/advanced-column-splitting-in-power-query/, which was written in collaboration */
/* with Curt Hagenlocher, Microsoft */
SplitByDelimiter = (table, column, delimiter) =>
let
/* Technique that turns table column into a List of characters, filters the list for the char and then counts the rows, */
/* adding 1 to get the result */
Count = List.Count(List.Select(Text.ToList(Table.Column(table, column){0}), each _ = delimiter)) + 1,

/* Creates the column names for the expanded columns */
Names = List.Transform(List.Numbers(1, Count), each column & "." & Text.From(_)),

/* Converts list values to data type text */
Types = List.Transform(Names, each {_, type text}),

/* Splits the multi-value field into separate columns */
Split = Table.SplitColumn(table, column, Splitter.SplitTextByDelimiter(delimiter), Names),

/* Converts the new columns to data type text */
Typed = Table.TransformColumnTypes(Split, Types)
in
Typed,

 

 

thanks!

1 ACCEPTED SOLUTION

Hi @MP_123,

 

Perhaps you can try to write a function to check the table columns which contain the specified delimiter.

 

For example:

let
    ContainColumn= (sourcetable as table, delimiter as text) =>
    let
        ColumnName= Table.ColumnNames(sourcetable),
        result= List.Transform(ColumnName, each if List.Count(List.Select(Table.Column(sourcetable , _ ),each try Text.Contains(_ ,delimiter) otherwise null))>0 then _ else null),
        RemoveNull=List.RemoveNulls(result)
    in
        RemoveNull
in
    ContainColumn

 

Invoke:

Capture3.PNG

 

Capture2.PNG

Capture4.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @MP_123,

 

I find a simple function to loop the table, you can take a look at below formula:

 

let
    Custom = (source as table) =>
    let
        FunctionToApply = (x as any) =>let result= x+1 in result,
        TransformList = List.Transform(Table.ColumnNames(source), each {_ , FunctionToApply}),
        Output = Table.TransformColumns(source, TransformList)
    in
        Output
in    
    Custom 

 

 

Reference link:

Applying a Function to Every Cell in a Table in Data Explorer (Power Query)

 

Notice, you can modify the "x+1" part to other functions.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

hi, thank you @v-shex-msft!!

 

i want to iterate on each cell and to split the cell by delimiter (i don't know the columns i want to split in advance)

can you please help me? i'm a bit complicated with the splitter function

 

thank you very much

Hi @MP_123,

 

Perhaps you can try to write a function to check the table columns which contain the specified delimiter.

 

For example:

let
    ContainColumn= (sourcetable as table, delimiter as text) =>
    let
        ColumnName= Table.ColumnNames(sourcetable),
        result= List.Transform(ColumnName, each if List.Count(List.Select(Table.Column(sourcetable , _ ),each try Text.Contains(_ ,delimiter) otherwise null))>0 then _ else null),
        RemoveNull=List.RemoveNulls(result)
    in
        RemoveNull
in
    ContainColumn

 

Invoke:

Capture3.PNG

 

Capture2.PNG

Capture4.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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