Forum Discussion

RAKESH1986's avatar
RAKESH1986
Helper II
3 years ago
Solved

How to group values in two groups-power query

Hi all,   i have these value i column, and i want to group these values in two group and take sum of another column values.         i want to group all red highligted in to one gro...
  • AlB's avatar
    3 years ago

    RAKESH1986 

    See it all at work in the attached file. Place the following 3 pieces of M code in a blank query each to see the steps

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZTdbsMgDIVfBUXaXTUB2U9vEfJapgAVOK2mro+x919RUBtTQnOVi/PJxzbHOZ+7Q/AaYuw2nTpxcf3wVy5fusumkOQkvVWkfpI+s2QOMBgH1YpEyyX7mpZrvt/svkEjs8qpHVhwSKrzNjX5CNGmJsdt7saC3itntBpYRIVGE0PRhCSZeQHqyfAzKPhEud0TQ4rJddV68ogIA2hv7ZhQNN7VLBcgargAUTvjIoYxLfzRrG8gksSrikxGIucgNYMhjV/zKFVJklaqeYQtiT2L6gvwp7auGlHkvELQRV0voXx/+ajQvucKvUdtjmZgv3+cyw+WdqdxDMVq5AqU+jVR2sAsjfujenZId2TxjO4I3ZtVCMGoW1vah+BjGTW5Ci4Oqg3PflaXfw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Discipline = _t, EARLY_AW_WK = _t, AW_EARLY_BASELINE = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Discipline", type text}, {"EARLY_AW_WK", type text}, {"AW_EARLY_BASELINE", Percentage.Type}}),
        #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Discipline] = "PROJECT MANAGEMENT")),
        #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Discipline", "EARLY_AW_WK"}, {{"AW_EARLY_BASELINE", each List.Sum([AW_EARLY_BASELINE]), type nullable number}})
    in
        #"Grouped Rows"

     

     

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZTdbsMgDIVfBUXaXTUB2U9vEfJapgAVOK2mro+x919RUBtTQnOVi/PJxzbHOZ+7Q/AaYuw2nTpxcf3wVy5fusumkOQkvVWkfpI+s2QOMBgH1YpEyyX7mpZrvt/svkEjs8qpHVhwSKrzNjX5CNGmJsdt7saC3itntBpYRIVGE0PRhCSZeQHqyfAzKPhEud0TQ4rJddV68ogIA2hv7ZhQNN7VLBcgargAUTvjIoYxLfzRrG8gksSrikxGIucgNYMhjV/zKFVJklaqeYQtiT2L6gvwp7auGlHkvELQRV0voXx/+ajQvucKvUdtjmZgv3+cyw+WdqdxDMVq5AqU+jVR2sAsjfujenZId2TxjO4I3ZtVCMGoW1vah+BjGTW5Ci4Oqg3PflaXfw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Discipline = _t, EARLY_AW_WK = _t, AW_EARLY_BASELINE = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Discipline", type text}, {"EARLY_AW_WK", type text}, {"AW_EARLY_BASELINE", Percentage.Type}}),
        #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Discipline] <> "PROJECT MANAGEMENT")),
        #"Grouped Rows" = Table.Group(#"Filtered Rows", {"EARLY_AW_WK"}, {{"AW_EARLY_BASELINE", each List.Sum([AW_EARLY_BASELINE]), type nullable number}}),
        #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Discipline", each "Group 1"),
        #"Reordered Columns" = Table.ReorderColumns(#"Added Custom",{"Discipline", "EARLY_AW_WK", "AW_EARLY_BASELINE"})
    in
        #"Reordered Columns"

     

     

     

    let
        Source = Table.Combine({T1, T2}),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Discipline", type text}, {"AW_EARLY_BASELINE", Percentage.Type}})
    in
        #"Changed Type"

     

     

    Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.