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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
sudanaditya
Regular Visitor

POWER QUERY -LOOP

Dear All - I have a scenario as below where I have a  CRP /SIT/UAT START AND END DATE FOR DIFFERENT PROJECT  .I need to have a conditional query which would take the CRP start date and CRP end date and plot it against each date with CRP based on the logic ,like wise it should loop in for SIT AND UAT for each PROJECT ROW

TIME LINE SAMPLE 2.PNG 

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

Hi @sudanaditya 

Finally, i figure out with result below

Capture8.JPG

Capture10.JPG

Code in Advanced editor

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKijKzzJU0lEyNNQ31DcyMLSEsC2Q2JZIbEMjGAeEYnUgBhhB+SQbExsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [project = _t, #"CRP start date" = _t, #"CRP end date" = _t, #"SIT start date" = _t, #"SIT end date" = _t, #"UAT start date" = _t, #"UAT end date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"project", type text}, {"CRP start date", type date}, {"CRP end date", type date}, {"SIT start date", type date}, {"SIT end date", type date}, {"UAT start date", type date}, {"UAT end date", type date}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"project"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Attribute.1", "Attribute.2", "Attribute.3"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", type text}, {"Attribute.3", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Attribute.3"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Attribute.1", "type"}, {"Attribute.2", "s/e"}, {"Value", "date"}}),
    #"Grouped Rows" = Table.Group(#"Renamed Columns", {"project", "type"}, {{"min", each List.Min([date]), type date}, {"max", each List.Max([date]), type date}, {"all", each _, type table [project=text, type=text, #"s/e"=text, date=date]}}),
    #"Expanded all" = Table.ExpandTableColumn(#"Grouped Rows", "all", {"s/e", "date"}, {"all.s/e", "all.date"}),
    #"Added Custom" = Table.AddColumn(#"Expanded all", "Custom", each let End = [max] in
List.Generate(()=> 
[min], 
each Duration.Days(End-_)>=0, 
each Date.AddDays(_,1))),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Removed Columns1" = Table.RemoveColumns(#"Expanded Custom",{"all.date", "min", "max", "all.s/e"})
in
    #"Removed Columns1"

 

 
Best Regards
Maggie
Community Support Team _ Maggie Li
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

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @sudanaditya 

Finally, i figure out with result below

Capture8.JPG

Capture10.JPG

Code in Advanced editor

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKijKzzJU0lEyNNQ31DcyMLSEsC2Q2JZIbEMjGAeEYnUgBhhB+SQbExsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [project = _t, #"CRP start date" = _t, #"CRP end date" = _t, #"SIT start date" = _t, #"SIT end date" = _t, #"UAT start date" = _t, #"UAT end date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"project", type text}, {"CRP start date", type date}, {"CRP end date", type date}, {"SIT start date", type date}, {"SIT end date", type date}, {"UAT start date", type date}, {"UAT end date", type date}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"project"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Attribute.1", "Attribute.2", "Attribute.3"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", type text}, {"Attribute.3", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Attribute.3"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Attribute.1", "type"}, {"Attribute.2", "s/e"}, {"Value", "date"}}),
    #"Grouped Rows" = Table.Group(#"Renamed Columns", {"project", "type"}, {{"min", each List.Min([date]), type date}, {"max", each List.Max([date]), type date}, {"all", each _, type table [project=text, type=text, #"s/e"=text, date=date]}}),
    #"Expanded all" = Table.ExpandTableColumn(#"Grouped Rows", "all", {"s/e", "date"}, {"all.s/e", "all.date"}),
    #"Added Custom" = Table.AddColumn(#"Expanded all", "Custom", each let End = [max] in
List.Generate(()=> 
[min], 
each Duration.Days(End-_)>=0, 
each Date.AddDays(_,1))),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Removed Columns1" = Table.RemoveColumns(#"Expanded Custom",{"all.date", "min", "max", "all.s/e"})
in
    #"Removed Columns1"

 

 
Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-juanli-msft
Community Support
Community Support

Hi @sudanaditya 

First i need to know your data struture, 

i assume you have table struture as below, then i can move to next step.

Capture13.JPG

 

We could refer to these articles to create a list or table with dates from min date to the max date.

https://www.kasperonbi.com/automatically-ranged-date-table-using-dax-and-m/

https://medium.com/@Konstantinos_Ioannou/powerquery-dynamic-date-dimension-table-filtering-f9201cf87...

Next we can add the list/table above to the table, then filter with the condition so to get the final result.

 

Please tell me the correct struture of your data so that i can achieve the final output.

 

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors