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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
tomshaw83
Helper I
Helper I

Filldown Query with conditions

 

Hi all,

 

I am looking to define a test period in power query, as displayed in the column below. I currently have a column indicating when a test starts/stops - but I want to somehow be able to mark all the data inbetween so I can groupby test_period and user (essentially i want to recreate the test_period column somehow)

I have looked at filldown/fillup using mutliple columns with limited success so far.

Any ides would be appreciated, 

Thanks
Tom

 

UserValueStart_StopTest_period
A3  
A6STARTtest
A7 test
A5 test
A9STOPtest
A5  
A6  
B4  
B5STARTtest
B2 test
B8 test
B2 test
B4STOPtest
B6  
1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

I'd suggest adding a Custom helper column to duplicate Start_Stop which you'll use Fill Down on.

Then you can define your Test_period column as

if [Custom] = "START" or ([Custom] = "STOP" and [Start_Stop] = "STOP") then "test" else null

 

Here's what the resulting table looks like:

AlexisOlson_0-1643388988433.png

 

Here is the full M code you can paste into your Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIGYgWlWB0IzwyIg0Mcg0LgIuYo8qYoPEuwav8AHNJmcJ4TkGWCwjNFsQgkYoQib4HCM8IwCW6tE8KiWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [User = _t, Value = _t, Start_Stop = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"User", type text}, {"Value", Int64.Type}, {"Start_Stop", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Text.Length([Start_Stop]) > 1 then [Start_Stop] else null, type text),
    #"Filled Down" = Table.FillDown(#"Added Custom",{"Custom"}),
    #"Added Custom1" = Table.AddColumn(#"Filled Down", "Test_period", each if [Custom] = "START" or [Custom] = "STOP" and [Start_Stop] = "STOP" then "test" else null, type text)
in
    #"Added Custom1"

View solution in original post

3 REPLIES 3
AlexisOlson
Super User
Super User

I'd suggest adding a Custom helper column to duplicate Start_Stop which you'll use Fill Down on.

Then you can define your Test_period column as

if [Custom] = "START" or ([Custom] = "STOP" and [Start_Stop] = "STOP") then "test" else null

 

Here's what the resulting table looks like:

AlexisOlson_0-1643388988433.png

 

Here is the full M code you can paste into your Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIGYgWlWB0IzwyIg0Mcg0LgIuYo8qYoPEuwav8AHNJmcJ4TkGWCwjNFsQgkYoQib4HCM8IwCW6tE8KiWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [User = _t, Value = _t, Start_Stop = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"User", type text}, {"Value", Int64.Type}, {"Start_Stop", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Text.Length([Start_Stop]) > 1 then [Start_Stop] else null, type text),
    #"Filled Down" = Table.FillDown(#"Added Custom",{"Custom"}),
    #"Added Custom1" = Table.AddColumn(#"Filled Down", "Test_period", each if [Custom] = "START" or [Custom] = "STOP" and [Start_Stop] = "STOP" then "test" else null, type text)
in
    #"Added Custom1"

Thanks again

jennratten
Super User
Super User

What should happen to the rows that have blank values in the start_stop and test period columns that are outside of start/stop periods?

jennratten_1-1643379129935.png

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.