Calculate total cost/time per completed project.

Vaguely

New Member
Joined
Feb 17, 2019
Messages
8
Hey all,

I have a set of data I'm trying to calculate the cost / time per completed project. A completed project is one that has gone to "Prod". (production).

I want to figure out a formula that takes the below data and calculates for me the COST (or time) spent on projects that are complete (have "Prod") and tell me what period it was completed in.

It would be amazing to figure out a user friendly / maintainable / scale able way of doing this

Example Final:
Period: 11 -> manually entered
Cost: 410 -> no idea how this work. thoughts (Index + Aggregate) or using pivot table?
Time: 148 -> (same as above)
Projects: 1 -> (Countifs should work here)

Project A:
Project NameProject StagePeriodCostTime Spent
ADev810521
ASit910853
ABat109455
AProd1110319

<tbody>
</tbody>
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
you mean like this


Excel 2007
ABCDEF
1Project NameProject StagePeriodCostTime Spenttotal time / cost
2ADev810521148 days
3ASit910853410 dollars
4ABat109455
5AProd1110319
Sheet1
Cell Formulas
RangeFormula
F2=SUMIF(A2:E5,"A",E2:E5) & " days"
F3=SUMIF(A2:E5,"A",D2:D5) & " dollars"
 
Last edited:
Upvote 0
I mean like this; It has to be tied back to be period specific.

PeriodCostTime Spent
10
0
200
300
...00
1000
11410148

<tbody>
</tbody>
 
Upvote 0
I'll update the data set so that it's more clear what i'm working with.


Project NameProject StagePeriodCostTime Spent
ADev810521
ASit910853
ABat109455
AProd1110319
BDev16648
BSit57027
BBat105370
CDev19037
CSit69427
CProd94870

<tbody>
</tbody>
 
Upvote 0
sorry for multiple posts, i can't seem to edit mine.

Essentially, I only want to sum the projects that have gone through the "PROD" stage. So in the updated sampel set, we would sum A & C but not B.

PeriodCostReleases
100
200
.........
92321
1000
114101

<tbody>
</tbody>
 
Upvote 0
Maybe something like this VBA
Assuming data is as follows:


Excel 2007
ABCDEFGH
1Project NameProject StagePeriodCostTime SpentProject NameCostDuration
2ADev810521C232134
3ASit910853
4ABat109455A410148
5AProd1110319
6BDev16648
7BSit57027
8BBat105370
9CDev19037
10CSit69427
11CProd94870
Sheet2


Code:
Sub MM1()
Dim lr As Long, r As Long, n As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
x = 0
n = 2
Range("F1").Value = "Project Name"
Range("G1").Value = "Cost"
Range("H1").Value = "Duration"

For r = lr To 2 Step -1
    If Range("B" & r).Value = "Prod" Then x = 1
    If x = 1 Then
     Range("F" & n).Value = Range("A" & r).Value
     Range("G" & n).Value = Range("G" & n).Value + Range("D" & r).Value
     Range("H" & n).Value = Range("H" & n).Value + Range("E" & r).Value
    End If
    If Range("A" & r).Value <> Range("A" & r - 1).Value Then
    x = 0
    n = n + 1
    End If
Next r
End Sub
 
Last edited:
Upvote 0
Improved code assumes data is on Sheet 2 and in columns as mentioned in my sample data

Code:
SSub MM2()
Dim lr As Long, r As Long, n As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
x = 0
n = 2
Range("F1").Value = "Project Name"
Range("G1").Value = "Cost"
Range("H1").Value = "Duration"
For r = lr To 2 Step -1
    If Range("B" & r).Value = "Prod" Then x = 1
    If x = 1 Then
        Range("F" & n).Value = Range("A" & r).Value
        Range("G" & n).Value = Range("G" & n).Value + Range("D" & r).Value
        Range("H" & n).Value = Range("H" & n).Value + Range("E" & r).Value
    End If
    If Range("A" & r).Value <> Range("A" & r - 1).Value Then
        x = 0
        n = Cells(Rows.Count, "F").End(xlUp).Row + 1
    End If
Next r
With Worksheets("Sheet2")
    .Sort.SortFields.Add Key:=Range("F1"), SortOn:=xlSortOnValues, Order:=xlAscending
        With Worksheets("Sheet2").Sort
            .SetRange Range("F1:H" & lr)
            .Header = xlYes
            .Orientation = xlTopToBottom
            .Apply
        End With
End With
End Sub
 
Last edited:
Upvote 0
This is helpful thank you so much! my own problem is that I actually have to pass this off after i'm done with it to slightly less technical people and I'm hoping that a simpler more bootleg solution would work here?

I still really appreciate your help though, the thinking in the VBA is definitely useful for logically interpreting the order.

I usually have some grasp of being able to figure it out, but this one is totally beyond me! No idea of what index, match, aggregate, or even supporting tables can do. My ultimate audience will be more a laymen... perhaps the vba is the right way to go in the end, but could we brainstorm a bit with the powerful excel functions / pivot tables? I think pivot tables are ruled out, but it does provide a nice aggregate per project. There just needs to be some sort of filter for it to display 1. next to a period in an aggregate form for that project & 2. sum only when 'prod' is seen. yea okay maybe pivot tables cant do that...
 
Upvote 0
There are forum members that can probably set it up with formulas, far better than I....but the VBA will allow for a dynamic number of projects and ranges.
If you don't get further replies in a day or so.....give it a BUMP by replying to your own post !!
 
Last edited:
Upvote 0
The ideal is for me to be able to generate a graph with the aggregated data to plot a trend line of the costs. (let's ignore time for now as it can be replicated with costs after).

So for each Period (1 - 12, representing months) it will have on average the cost / completed project.

fundamentally this is how i think about it:
let table x = table that we will put this formula and be structured as the OUTPUT table. (same as the 3 column table as per previous post)
Let table y = table for input data 5 column table as per previous posts.
assume each project can have multiple stages not listed and repeating stages, but only 1 prod stage.

0. look at the table x, col1row1 to identify period. index()
1. Look (match) into column B - Stage and identify "Prod"
2. Return Project Value - A,B,C,D,E if found matching above
3. aggregate all values returned by value above sumif
4. Loop for all other "prods" in period??????????????????????? how............... stuck here;
 
Upvote 0

Forum statistics

Threads
1,215,593
Messages
6,125,716
Members
449,254
Latest member
Eva146

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top