Link to home
Start Free TrialLog in
Avatar of Ali Shah
Ali ShahFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to aggregate the values from child objectives to parent objectives and so on

Hi there,
I am developing the Performance Management System for our organisation. There can be one or more than one child of an objective and the child objectives can also have one or more child objectives and this can go on and on. The values can be only entered at the final leaf.  Please see the attached diagrame for more explanation.

User generated image
To achieve this i have and Objective table with (Objid PK, ObjName, AggType(Avg,Sum etc))

to create the hierarchy created the the following table
ObjDepend(DependID, ParentID FK Obj, ChildID FK Obj)

Each Objective can have one or more than one measure
MeasureDefs(MeasID, MeasDescp)
OMPairs (ObjID - MeasID PK, Formula etc)

The values are entered in the following table
ObjValues(ObjID-MeasID FKOmPairs, Actualv, TargetV, PeriodDate)

Now i need to calculate the values of child nodes depending on the aggregation type set in the objectives table(SUm, Avg, Max, Min) and set the value of the parent. But as it can be any level so i am stuck as how to find all the objectives in the tree and update them accordingly?

Sorry if i couldn't explain it properly but really looking forward to solve this.

regards,
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

If things can have only one parent then why not have the containers for the child as a member of the parent (tree like, which is your diagram above).
Then to find the value of all the child object the parent just loops through all the items in the container (think recursion, the child can calculate the value of all of its children and so on).
Not sure if it helps, but I recently write an article on SQL Server GROUP BY solutions that has a lot of grouping code you can work with, although you'll have to incorporate id-parent_id for it to be useful.
Avatar of Ali Shah

ASKER

Thanks for you comments.
Andy actually i am only a beginner to middle level developer in C#/ASP.Net. however with your help i am sure i can achieve this..

So do i need to create a unity container first and then use recursion in C# and loop through unity container?

Can you please also guide me creating the unity container for my specific requirements?

kindest regards,
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry i became busy with other stuff and coming back to it again. so it means that if i have the values in my datareader and i create a recursive method in C# it will work?
Yes.  My short example is a simple demonstration of one way to accomplish what you ask for.
Well well starting again on it. Too many projects at the moment