Forum Discussion

sudanaditya's avatar
sudanaditya
Regular Visitor
6 years ago
Solved

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 a...
  • v-juanli-msft's avatar
    6 years ago

    Hi sudanaditya 

    Finally, i figure out with result below

    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.