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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Replicating SQL nested queries in Power Query

hi all!

 

Suppose that I have a table that looks like this:

pmajlessi_0-1733336145353.png

I want to add a column like below:

pmajlessi_1-1733336181246.png

The new column, "info" literally looks into the column "information" and if it couldn't find a value there, it looks at the last row with a value and copies it in.

I can solve this in MSSQL by the below code:

select 
[id]
,[info] = case 
	when [information] = '' 
		then (select [information] from dbo.table where [id] = (select max([id]) from dbo.table where [id] < src.[id] and [information] <> ''))
	else [information]
end
from dbo.table as src

How can i replicate that in Power Query's M Language?

I tried List.Select but it gave me errors.

 

your help is much appreciated!

1 ACCEPTED SOLUTION
tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi  @Anonymous ,

How about this? 🙂

tackytechtom_6-1733343869215.png

 

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUaqorFKK1YlWMgKyE5OSwWxjIBvMMIExTGEMMyAjIy8bzDaHCVrAGJYwA2MB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [id = _t, information = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"information", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "info", each if [information] = "" then null else [information]),
    #"Filled Down" = Table.FillDown(#"Added Custom",{"info"})
in
    #"Filled Down"


Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

2 REPLIES 2
tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi  @Anonymous ,

How about this? 🙂

tackytechtom_6-1733343869215.png

 

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUaqorFKK1YlWMgKyE5OSwWxjIBvMMIExTGEMMyAjIy8bzDaHCVrAGJYwA2MB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [id = _t, information = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"information", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "info", each if [information] = "" then null else [information]),
    #"Filled Down" = Table.FillDown(#"Added Custom",{"info"})
in
    #"Filled Down"


Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Anonymous
Not applicable

Sir, you are a genius!
this was so simple, yet when I tried "Column from example" feature, it couldn't offer me a solution.

brilliant! who would have thought?

the entire day i was searching for solutions using "List.Select", "List.PostionOf" and "List.Generate" and their related errors, and all this time it was a built in feature, that only if I searched for Table.FillDown I could have found it much earlier, and saved myself a great deal of headache!

I love this forum!

and I love Power BI!

and Sir, thank you very much, you are a life saver!

Wish you all the best!

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.