Looping through a table

Moragtao

New Member
Joined
Jun 6, 2019
Messages
1
I'm attempting to create a table to store all of my functions in. What I would like to do is have power query loop through this table and load in all the functions in said table, but I can't seem to find any way to make this happen. I assume there is a way, I just don't know enough yet about power query to make it happen. Does anyone know how to go about doing this, or can point me in the right direction?
 

Some videos you may like

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

cyborgski

New Member
Joined
Jun 17, 2019
Messages
5
Hi,

Sorry, I am not good with the formatting on the message board. And the board will not allow me to upload an attachment.

Below is a sample table called calcs that contains Field name, the formula and the type information.
Field

<tbody>
</tbody>
Expression

<tbody>
</tbody>
Type

<tbody>
</tbody>
sum

<tbody>
</tbody>
List.Sum({[a],})

<tbody>

</tbody>


<tbody>
[TD]
type number

<tbody>
</tbody>
[/TD]

[TR]
[TD]
subtract

<tbody>
</tbody>
[/TD]
[TD]
[a]-

<tbody>

</tbody>

[/TD]
[TD]
type number


<tbody>
</tbody>
[/TD]
[/TR]
</tbody>


In your query that contains the data, add the boldfaced line.let
Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"a", Int64.Type}, {"b", Int64.Type}}),
AddColumns = List.Accumulate(List.Buffer(Table.ToRecords(Calcs)), #"Changed Type",
(s,c) => Table.AddColumn(s, c[Field], each Expression.Evaluate(c[Expression],[_=_] & #shared ), Expression.Evaluate(c[Type], #shared )))
in
AddColumns



#"Change Type" would be one of your steps in your query. I have not tried this in a real transform yet so I do not know how well it performs. I would think adding the columns in your query would be more efficient. Are you looking to reduce the number of lines in your transform?

Good luck and let me know how it works for you,
Mike
 

Watch MrExcel Video

Forum statistics

Threads
1,099,753
Messages
5,470,571
Members
406,707
Latest member
drkjz

This Week's Hot Topics

Top