Forum Discussion

SEMattis's avatar
SEMattis
Advocate III
6 years ago
Solved

Aggregation after join

Hi,

 

I'm currently putting together a report regarding the allocation of my workforce in which I'm trying to aggregate values for indirect allocations for a resource. The issue at hand is that I can only use a table that aggregates resource values per project or product team (See below). I have attempted to merge the queries using two available keys (that are crucial for the aggregation to work) the Resource Key and the Period Key. The merge works fine it is when I attempt to use the "Expand - Aggregate" functionality that things go wrong. Since the table (Team table below) I'm trying to aggregate values from contains 950,000 rows the aggregation does not complete (Tried running it for 2 hrs yesterday without completion). 

 

To be clear there is no direct relationship between these two tables as it would be a many-to-many relationship.

 

Is the merge + expand - aggregate my only option or do you see any alternatives?

 

In my Resource Table (the table in which I have a summary of the resources' allocation per month accordingly:

 

Resource Table:

Resource KeyPeriod Key (Month)Allocation (HRS)Indirect Allocation (Aggregated from table below)
5555555555555518090
11111111111111900

 

Since my resources can be allocated to many different parts of my organisation (in projects, product teams etc) I also have a table that aggregate allocations around the teams in which the resources work in:

Resource KeyPeriod Key (Month)Team KeyAllocation (HRS)Activity TypeIndirect Allocation
55555555555555190Run0
55555555555555240Indir40
55555555555555350Indir50
11111111111111190Run0

 

THANKS!

  • ImkeF's avatar
    ImkeF
    6 years ago

    Hi

    coming to think about it, one should probably start with the aggregation and do the merge afterwards:

     

    let
        Source = Team,
        GroupAndAggregateFirst = Table.Group(Source, {"Resource Key", "Period Key (Month)"}, {{"Sum HRS", each List.Sum([#"Allocation (HRS)"]), type number}, {"Sum Indirect", each List.Sum([Indirect Allocation]), type number}}, GroupKind.Local),
        ThenMergeRightOuter = Table.NestedJoin(GroupAndAggregateFirst, {"Resource Key", "Period Key (Month)"}, Resource, {"Resource Key", "Period Key (Month)"}, "Resource", JoinKind.RightOuter),
        #"Expanded Resource" = Table.ExpandTableColumn(ThenMergeRightOuter, "Resource", {"Allocation (HRS)"}, {"Allocation (HRS)"})
    in
        #"Expanded Resource"

    This uses the GroupKind.Local-option that returns results much faster. But it requires the groups to exist in sequential order already (like in the example you've given). If thats not the case in your original data, please delete that optional argument.

     

    See also attached file.

     

5 Replies

    • SEMattis's avatar
      SEMattis
      Advocate III

      Hej ImkeF ,

       

      Thank you for the suggested solution. I tried the solution this morning but it is more or less just as slow as the aggregation I'm afraid. 

       

      Do you think it has to do with the fact that I am using two keys (Resource Key & Period Key) when doing the merge?

       

      //SEMattis

      • ImkeF's avatar
        ImkeF
        Community Champion

        Hi

        coming to think about it, one should probably start with the aggregation and do the merge afterwards:

         

        let
            Source = Team,
            GroupAndAggregateFirst = Table.Group(Source, {"Resource Key", "Period Key (Month)"}, {{"Sum HRS", each List.Sum([#"Allocation (HRS)"]), type number}, {"Sum Indirect", each List.Sum([Indirect Allocation]), type number}}, GroupKind.Local),
            ThenMergeRightOuter = Table.NestedJoin(GroupAndAggregateFirst, {"Resource Key", "Period Key (Month)"}, Resource, {"Resource Key", "Period Key (Month)"}, "Resource", JoinKind.RightOuter),
            #"Expanded Resource" = Table.ExpandTableColumn(ThenMergeRightOuter, "Resource", {"Allocation (HRS)"}, {"Allocation (HRS)"})
        in
            #"Expanded Resource"

        This uses the GroupKind.Local-option that returns results much faster. But it requires the groups to exist in sequential order already (like in the example you've given). If thats not the case in your original data, please delete that optional argument.

         

        See also attached file.