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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

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,101,886
Messages
5,483,512
Members
407,397
Latest member
HerbA

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top