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
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)


@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
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.