cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Power Query Using a Value from some previous step

Hello friends,

I have an Events table with a EventDate column.

I am doing some transformations in the table where I want to use Max(EventDate) for the whole table

How do I implement this without having to create another query?

Thank you

Michael

1 ACCEPTED SOLUTION
v-qiuyu-msft
Community Support
Community Support

Hi @Anonymous,

 

Here is a sample Power Query for you to return MAX date of some previous steps. You can download attached .pbix to have a look.

 

z6.PNGz7.PNGz8.PNG

 

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-qiuyu-msft
Community Support
Community Support

Hi @Anonymous,

 

Here is a sample Power Query for you to return MAX date of some previous steps. You can download attached .pbix to have a look.

 

z6.PNGz7.PNGz8.PNG

 

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thank you friends,

So I can just refference any previoust step and it remembers it?

Can I also join (merge) a current step with a table from let's say three steps before?

Thank you!

Michael

Within a query, you can reference any other step, before or after the current step (beware of circular references though).

 

Power Query has the concept of immutability, meaning that data is becer changed; only new data is added.

So even if it looks like you are changing values (like with transforming column values), actually a new table is created.

And you can reference each of these versions by its step name.

That is: as long as you are in the query editor.

Once the query is ready and tables are re(loaded), the story is completely different: the entire query is evaluated as one unit and there is some smart logic behind it to do that efficiently.

E.g. with query folding, the entire query is evaluated as 1 SQL-statement that is fired to the database server.

 

Another example is code that may look highly inefficient on first sight, but appears highly effeicient while refreshing your data, e.g. if you want to use data from the previous row (not the previous step), it looks efficient to reference that row with an index number, but in practice it is way faster to create 2 index columns (one starting with 0 and the other with 1) and then merging the table with itself, joining on the different index columns, so you will have all required data on the same row.

 

Specializing in Power Query Formula Language (M)
RY33
Frequent Visitor


@MarcelBeug wrote:

Within a query, you can reference any other step, before or after the current step (beware of circular references though).

 

Power Query has the concept of immutability, meaning that data is becer changed; only new data is added.

So even if it looks like you are changing values (like with transforming column values), actually a new table is created.

And you can reference each of these versions by its step name.

That is: as long as you are in the query editor.

Once the query is ready and tables are re(loaded), the story is completely different: the entire query is evaluated as one unit and there is some smart logic behind it to do that efficiently.

E.g. with query folding, the entire query is evaluated as 1 SQL-statement that is fired to the database server.

 

Another example is code that may look highly inefficient on first sight, but appears highly effeicient while refreshing your data, e.g. if you want to use data from the previous row (not the previous step), it looks efficient to reference that row with an index number, but in practice it is way faster to create 2 index columns (one starting with 0 and the other with 1) and then merging the table with itself, joining on the different index columns, so you will have all required data on the same row.

 




Thnkas for your sharing @MarcelBeug Smiley Happy

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Great stuff,

Thanks, @MarcelBeug

Michael

MarcelBeug
Community Champion
Community Champion

Maybe something like this:

 

let
    Source = Events,
    MaxDate = List.Max(Source[EventDate])
in
    MaxDate
Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors
Top Kudoed Authors