Forum Discussion

adavid999's avatar
adavid999
Helper V
6 years ago
Solved

create new groups from existing table

Dear all, I am working in power query/excel. Is it possible/uncomplicated to group some items in an existing external odata table into new categories so that any measures/displays pick up both new g...
  • Jimmy801's avatar
    6 years ago

    Hello adavid999 

     

    you can try to add a new column with the new region name

    Group by this column, applying exactly the measures you want and after that combining both tables. Here the code for a short example

    let
    	Source = #table
    	(
    		{"Region","%","resp"},
    		{
    			{"x","5","2"},	{"y","10","3"},	{"y","15","4"}
    		}
    	),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"%", type number}, {"resp", type number}}),
        #"Added Custom" = Table.AddColumn(Table.RemoveColumns(#"Changed Type", "Region"), "Region", each "group xyy"),
        #"Grouped Rows" = Table.Group(#"Added Custom", {"Region"}, {{"%", each List.Average([#"%"]), type number}, {"resp", each List.Sum([resp]), type number}}),
    	Combine = Table.Combine({#"Changed Type", #"Grouped Rows"})
    in
        Combine

     

    Copy paste this code to the advanced editor in a new blank query to see how the solution works.

    If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
    Kudoes are nice too

    Have fun

    Jimmy