The Outline Level step does nothing but change how the data is displayed, it doesn’t actually change anything in the database. So the first three of your Outline Level steps ultimately have no effect, since each one simply changes the display. The end result is simply as if you had only the last step, and only the Sub_Account summaries will be displayed. You can then expand or collapse the summaries manually, as described on this help page.
You won’t be able to calculate the percentage you want with the Summarize & Analyze dialog, but it can be done with a procedure. Let’s start with a procedure that does what your analysis does. You could get this procedure using the procedure recorder, or just type it in.
field "Expense Type"
groupup
field "Main Categories"
groupup
field Account
groupup
field Sub_Account
groupup
field Amount
total
outlinelevel 1
I’ve left out the Sort Down step, I’ll discuss that further in a moment. I also left out all but the last outline level step.
To calculate the percentage, you’ll need to add another numeric field to your database, I’ll assume it is called Percentage. Then you will add four lines to the end of the code:
lastrecord
let grandtotal = Amount
field Percentage
formulafill Amount*100/grandtotal
The first line moves the active record to the last record of the database, which now contains the grand total. The second line copies the grand total amount into a new variable, which I’ve named grandtotal (it could be named anything, as long as you are consistent). The third line makes the Percentage field active, so we can perform a calculation. The final line actually performs this calculation for every visible record in the database, which in this case will include all of the summary records. If you moved these four lines up one line, so that they were between the total and outlinelevel statements, it would calculate the percentage of every transaction relative to the grand total.
Now, back to sorting. The way you have set it up it will sort the detail records within each Sub_Account. I’m guessing that what you actually want is to sort the summaries, If you want the Sub_Account summaries sorted within the Accounts, and those sorted within the Main Categories, and those between the Expense Types, and then those sorted down, you would need to add multiple sorts at the end of the code, like this:
field Amount
sortdown
outlinelevel 2
sortdown
outlinelevel 3
sortdown
outlinelevel 4
sortdown
So here is your complete program. I’ve also added a startdatabasechange statement at the top, so that you can use the Undo command after running this program, and also noshow and endnoshow statements which turn off the display while this code is running, so that you don’t have to watch it update the display over and over again as each step runs.
startdatabasechange "allrecords"
noshow
field "Expense Type"
groupup
field "Main Categories"
groupup
field Account
groupup
field Sub_Account
groupup
field Amount
total
outlinelevel 1
lastrecord
let grandtotal = Amount
field Percentage
formulafill Amount*100/grandtotal
field Amount
sortdown
outlinelevel 2
sortdown
outlinelevel 3
sortdown
outlinelevel 4
sortdown
endnoshow
showpage
Here are some help pages for topics used in this program.