Forum Discussion

artfulmunkeey's avatar
6 years ago
Solved

Issue matching (dates) MS Project Capacity & demand to calculate utilisation

Hi all, I am relatively new to Power Queries and have been learning through trial and error.   I have one particular issue which I have been struggling with for some time and various attempts to so...
  • Jimmy801's avatar
    6 years ago

    Hello artfulmunkeey 

     

    here another approach.

    Check it out

    let
        Demand = 
        let
    	Source = #table
    	(
    		{"Proejct ID","Resource ID","Date","Demand"},
    		{
    			{"Project 1","Resource 1","Jan-20","100"},	{"Project 1","Resource 1","Feb-20","80"},	{"Project 1","Resource 1","Mar-20","120"},	{"Project 1","Resource 2","Feb-20","100"},	
    			{"Project 1","Resource 2","Mar-20","80"},	{"Project 1","Resource 3","Jan-20","100"},	{"Project 2","Resource 1","Feb-20","20"},	{"Project 2","Resource 1","Mar-20","30"},	
    			{"Project 2","Resource 2","Mar-20","20"},	{"Project 2","Resource 2","Apr-20","50"},	{"Proejct 2","Resource 3","Feb-20","100"}
    		}
    	),
        changetype = Table.TransformColumnTypes(Source, {{"Demand", Int64.Type}}),
    	AddMonthYear = Table.AddColumn(changetype, "MonthYear", each Text.From(Date.Month(Date.From([Date]))) & "-" & Text.From(Date.Year(Date.From([Date])) ))
        in
    	    AddMonthYear,
    
    	Capacity = 
    	let
    	Source = #table
    	(
    		{"Resource ID","Date","Capacity"},
    		{
    			{"Resource 1","01/01/2020","8"},	{"Resource 1","02/01/2020","8"},	{"Resource 1","03/01/2020","8"},	{"Resource 1","04/01/2020","8"},	{"Resource 2","01/01/2020","8"},	
    			{"Resource 2","02/01/2020","8"},	{"Resource 2","03/01/2020","8"},	{"Resource 2","04/01/2020","8"},	{"Resource 3","01/01/2020","8"},	{"Resource 3","02/01/2020","8"},	
    			{"Resource 3","03/01/2020","8"},	{"Resource 3","04/01/2020","8"}
    		}
    	),
    	changetype = Table.TransformColumnTypes(Source, {{"Capacity", Int64.Type}}),
    	AddMonthYear = Table.AddColumn(changetype, "MonthYear", each Text.From(Date.Month(Date.From([Date]))) & "-" & Text.From(Date.Year(Date.From([Date])) ))
    	in
    		AddMonthYear,
    	Join = Table.NestedJoin(Demand, {"Resource ID", "MonthYear"}, Capacity, {"Resource ID", "MonthYear"}, "Capacity"),
        #"Aggregated Capacity" = Table.AggregateTableColumn(Join, "Capacity", {{"Capacity", List.Sum, "Sum of Capacity"}})
    in
        #"Aggregated Capacity"

     

    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