Click here to Skip to main content
15,891,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two tables, one an invoice table and the other a hierarchy table for the accounts on the invoice

Invoice Table:

| InvoiceNo| AccNo| InvoiceAmount |
    --------------------------------------
    | A1234| 345| 100.00   |
    | A1235| 346| 95.00    |
    | A1236| 347| 15.50    |
    | A1237| 348| 20.10    |


Hierarchy Table

| AccNo| HierAccNo| Level|
    --------------------------------------
    | 123|    | 1    |
    | 789| 123| 2    |
    | 890| 123| 2    |
    | 345| 789| 3    |
    | 346| 789| 3    |
    | 347| 890| 3    |
    | 348| 890| 3    |



What I'm trying to do is to roll up the amounts from the invoice table to the highest level AccNo which is Level1 and then on a seperate instance from the highest account number roll back down to the next levels.

What I have tried:

So far I am able to roll up to the highest band number by the following :

C#
var BandL2 = from invoice in db.Invoices//Roll up to level 2
                             join ban in db.HierarchyTable
                             on invoice.AccNo equals ban.Ban
                             where invoice.GlobalInvoiceID == globalInvoice.Id
                             group invoice by ban.HierAccNo into bandHierarchy
                             select new
                             {
                                 Level2Band = bandHierarchy.Key,
                                 Amount = bandHierarchy.Sum(m=> m.InvoiceAmount)
                             };

                var bandHierarchyTable = db.HierarchyTable.AsQueryable();

                var BandL1 = from band2 in BandL2 // Roll Up to level 1
                             join band1 in bandHierarchyTable
                             on band2.Level2Band equals band1.Ban
                             group band2 by band1.HierAccNo into bandL1
                             select new
                             {
                                 Level1Band = bandL1.Key,
                                 Amount = bandL1.Sum(m => m.Amount)
                             };

But now I'm having an issue reversing the process and drilling down from Level 1 as the only details from the form is the AccNo of Level 1(eg. 123).
I'm trying to do this on the fly using pop up modals as I'm drilling.

How do I drill down again so that I can get level by level amounts?
Example:

Ouput Table from Above Code


| AccNo| Amount|
    --------------------------------------
    | 123| 230.60 |


Then

| AccNo| Amount|
    -------------------------------------- 
    | 789| 195  | 
    | 890| 35.60|

And then clicking on one of the AccNo.

| AccNo| Amount|
    -------------------------------------- 
    | 345| 100| 
    | 346| 95 |



Thanks!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900