How to Rank the Data for each Group in Power Query | Power BI Analytics Kingdom


let

    SourceData = “dY49C8IwEIb/SsncQaioq1alCF2k4FAynOlBD2Ou5EP8+cYMVaxd7ut5795rW3HQqLxlQ8qJXFRgu2xPTsW6EDL/5WfoiGNe/mMcPNoZ2KDGBzliE5t1EhyDNeSDxTjZYRfjajIve6DPyW/SwFXjuFPxHbPtMGgCo/BteAHX16B6Mjg6TlUl8y39vJkR1PRMvJjhp0AqCRZCyhc=”,

    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText(SourceData, BinaryEncoding.Base64), Compression.Deflate)), 

        let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ProdSegment = _t, ProdName = _t, OrderQnty = _t]),

    ChangedType = Table.TransformColumnTypes(Source,{{“ProdSegment”, type text}, {“ProdName”, type text}, {“OrderQnty”, Int64.Type}}),

    SegmentGroupData = Table.Group(ChangedType, {“ProdSegment”}, {{“ProdSegGroup”, 

        each _, type table [ProdSegment=nullable text, ProdName=nullable text, OrderQnty=nullable number]}}),

    RankQnty = Table.AddColumn(SegmentGroupData, “RankByProdQnty”, each Table.AddRankColumn([ProdSegGroup], 

        “RankProdQnty”,{{“ProdSegment”,Order.Ascending},{“OrderQnty”,Order.Descending}},[RankKind = RankKind.Dense])),

    SelectColumns = Table.SelectColumns(RankQnty,{“RankByProdQnty”}),

    ExpandRankByProdQnty = Table.ExpandTableColumn(SelectColumns, “RankByProdQnty”, 

        {“ProdSegment”, “ProdName”, “OrderQnty”, “RankProdQnty”}, 

        {“Prod_Segment”, “Prod_Name”, “Order_Qnty”, “Rank_ProdQnty”})

in

    ExpandRankByProdQnty 



Source link

Be the first to comment

Leave a Reply

Your email address will not be published.


*