Results 1 to 5 of 5
  1. #1
    michaelh93 is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    8

    A Summing "Heirachy"

    Hi,

    I am working on a database that it used to calculate power consumption. Each item is assigned to a specific substation where it gets it power. So for example if you have 10 1 watt light bulbs attached to the substation, the total power drawn would be 10 watts.

    This total power per substation is calculated by a query that sums all of the different values for each item and presents the combined total next to the substation name.

    What makes this more difficult is the fact that some substations get their power from other substations, making the total power from the main substation effectively the sum of the components attached to both.

    For example: substation A has 10 watts worth of light bulbs and substation B has 15 watts worth of light bulbs. Substation A is "feeding" power to substation B, so the total power drawn from substation A is 25W and the total power drawn from substation B is 15W.

    The table that holds the substation data has a field that identifies which substation is gets its power from, assuming it is not independant.

    Currently my query can sum all of the components entered under substation A but what I need, but cannot do, is for the total of substation B to be included with the total of substation A. (In the case that A is "feeding" B.)


    How can I go about this. It might be simple but I can't think of anything.

    Thanks

  2. #2
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    The feasibility and/or ease of the solution will depend upon your database/table design. Could you post that, preferably as a relationship diagram. In any event the solution will not be trivial.

  3. #3
    michaelh93 is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    8
    Quote Originally Posted by Rod View Post
    The feasibility and/or ease of the solution will depend upon your database/table design. Could you post that, preferably as a relationship diagram. In any event the solution will not be trivial.
    This is my first ever database, and is quite complex (at least to me) so I can assure you the structure is less than ideal. (Probably quite bad, my makeshift solution to this problem is sketchy at best.). It is functional at this point, and if the solution may be difficult it might be in my best intrest to stick with what I have, although when i start testing it may turn out that I need to re-write this.

    *Symptomatic of my lack of training in Access is that I haven't used the database wide relationship window :S

  4. #4
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    OK, good luck.

    Let me mention - perhaps for the future - that hierarchies are tricky. Your requirement sounds fairly basic and you can set it up by including a recursive relationship between substations. (Identical situations occur for manager/supervisor/staff and parent/child relationships.) For more formal and/or complex situations there is an ActiveX object called TreeView but the documentation for this is 'patchy.'

    Whichever solution you use, trying to sum all nodes in a branch using a single SQL query is a nightmare; I'm not even sure it's possible unless you allow restrictions on the depth of the recursion. Instead you will be involved in what is often called 'chain chasing.' It's not that difficult - somewhat akin to juggling with three balls - but once set up will work for any entry point in the hierarchy and for any depth of hierarchy (levels of recursion).

  5. #5
    michaelh93 is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    8
    Thank you Rod.

    You have been most helpful.

    EDIT: Turns out I'll need to implement chain chasing after all, my design criteria has expanded. Wish me luck.

    EDIT 2: I can't find any good sources on chain chasing, can you recommend any? Thanks again.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 11-14-2012, 04:47 PM
  2. Export "Query or Report" to a "Delimited Text File"
    By hawzmolly in forum Import/Export Data
    Replies: 3
    Last Post: 08-31-2012, 08:00 AM
  3. Replies: 11
    Last Post: 03-29-2012, 02:32 PM
  4. Replies: 16
    Last Post: 07-22-2011, 09:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums