Google Sheets - How to create a macro that sorts transactions and automatically subtotals them and returns the subtotal values in a separate sheet - function

In Google sheets I have a transaction sheet that tracks my share portfolio. Each time I buy a share I enter the symbol, number of shares, price etc in the sheet. I am trying to create a macro that will sort and automatically subtotal the sorted range at each change in ticker symbol.
My question is how do you automatically insert a subtotal for each change in ticker symbol?
example:
MSFT 100 shares $ 250 total 25 000
MSFT 50 shares $ 100 total 5000
SUBTOTAL MSFT 150 shares total 30 000
APPL 100 shares $ 250 total 25 000
APPL 50 shares $ 100 total 5000
SUBTOTAL APPL 150 shares total 30 000
I can sort the data easily but have only found tutorials on how to manually use the subtotal value.
Any help will with automating the subtotal function will be appreciated

Related

Sum of all the different column values group by another column?

I have a table like this:
project_name janExp febExp marchExp aprilExp
project A 1000 1100 1200 1300
project B 2000 2100 2200 2300
project C 3000 3100 3200 3300
project A 500 600 700 800
project B 100 200 300 400
I want output like this:
project_name janExp febExp marchExp aprilExp
Project A 1500 1700 1900 2100
Project B 2100 2300 2500 2700
project C 3000 3100 3200 3300
I am new to Qlikview, can someone tell me what expression i need to write for it?
Just create a straight table!
Your script should look like this:
You can see the expression in the title. Use the Field 'project_name' as a dimension:
Select
project_name,
Sum (janExp),
Sum (febExp),
Sum (marchExp)
From table
Group by project_name
Check the following script. Note that the GROUP BY and the SUM() are in the LOAD part. This is the set of expressions used by QlikView. You can also do this in two steps, by performing a resident load then a group by in SQL part.
Load
project_name,
sum(janExp) as janExp,
sum(febExp) as febExp,
sum(marchExp) as marchExp
Group By
project_name;
SQL
Select * From table;

SSRS Tablix (Expand Collapse)

I have a tablix that pivots data in the following way
Agent Brochure1 Brochure2 Brochure3
xyz 10 15 25
The client wants a total column for all the brochure and the ability to expand the total to display the individual quantities. e.g.
Agent Total
xyz 50
Agent Total Brochure1 Brochure2 Brochure3
xyz 50 10 15 25
Is this possible?
Thanks

Access Calculated Field

I am having difficulty trying to make a calculated field that I need. So here is what I am trying to do:
I have a query that combines the information based on three tables. The most important fields that for the application are as follows:
Family Income Age Patient
15,000 18 Yes
28,000 25 No
30,000 1 Yes
From here I want to make a calculated field that gives the correct program the patient was enrolled in. based on these fields ie:
Program Minimum Income Maximum Income Minimum Age Maximum Age Patient
Children's 0 20,000 1 19 Yes
Adult 0 12,000 19 65 No
Non Patient 0 20,000 1 19 No
Adult 2 12,000 50,000 19 65 No
Etc.
to create:
Family Income Age Patient Program
15,000 18 Yes Children's
28,000 25 No Adult 2
30,000 1 Yes Children's 2
I know I can use IIf to hard code it in to the field, but then it will be really difficult for other people to update the information as the guidelines change. Is it possible to have the information stored in a table? and use the information on the table form etc, or will I need to use IIf
Any Ideas? is it possible to dynamically create the IIf in SQL using VBA while pulling the information from the table?
EDIT:::
Thank you for your response and for formatting my tables, I still have no idea how you changed it, but it looks amazing!
I tried to add the SQL you added down below, but I was not able to make it work. I'm not sure if I made a mistake so I included the SQL of my Query. The query currently returns 0 values, so I think I messed something up. (The real Query is embarassing...I'm sorry for that). Unfortunately, I have done everything in my power to avoid SQL, and now I am paying the price.
SELECT qry_CombinedIndividual.qry_PrimaryApplicant.[Application Date],
qry_CombinedIndividual.qry_PrimaryApplicant.[Eligibility Rep],
qry_CombinedIndividual.qry_PrimaryApplicant.Name,
qry_CombinedIndividual.qry_PrimaryApplicant.Clinic,
qry_CombinedIndividual.qry_PrimaryApplicant.Outreach,
qry_CombinedIndividual.qry_PrimaryApplicant.[Content Type ID],
qry_CombinedIndividual.qry_PrimaryApplicant.[Application Status],
qry_CombinedIndividual.qry_PrimaryApplicant.Renewal,
qry_CombinedIndividual.qry_Enrolled.EthnicityEnr,
qry_CombinedIndividual.qry_Enrolled.GenderEnr, qry_CombinedIndividual.AgeAtApp,
qry_CombinedIndividual.[Percent FPL], tbl_ChildrensMedical.MinPercentFPL,
tbl_ChildrensMedical.MaxPercentFPL, tbl_ChildrensMedical.MinAge,
tbl_ChildrensMedical.MaxAge, tbl_ChildrensMedical.Program
FROM qry_CombinedIndividual
INNER JOIN tbl_ChildrensMedical ON qry_CombinedIndividual.qry_Enrolled.Patient = tbl_ChildrensMedical.Patient
WHERE (((qry_CombinedIndividual.AgeAtApp)>=[tbl_ChildrensMedical].[MinAge]
And (qry_CombinedIndividual.AgeAtApp)<[tbl_ChildrensMedical].[MinAge])
AND ((qry_CombinedIndividual.[Percent FPL])>=[tbl_ChildrensMedical].[MinPercentFPL]
And (qry_CombinedIndividual.[Percent FPL])<[tbl_ChildrensMedical].[MaxPercentFPL]));
Also there are many different programs. Here is the real Children's Table (eventually I would like to add adults if possible)
*Note the actual table uses FPL (which takes family size into account, but is used the same as income). I am again at a total loss as to how you formated the table.
Program Patient MinPercentFPL MaxPercentFPL MinAge MaxAge
SCHIP (No Premium) No 0 210 1 19
SCHIP (Tier 1) No 210 260 1 19
SCHIP (Tier 2) No 260 312 1 19
Newborn No 0 300 0 1
Newborn (Patient) Yes 0 300 0 1
Children's Medical Yes 0 200 1 19
CHIP (20 Premium) Yes 200 250 1 19
CHIP (30 Premium) Yes 250 300 1 19
Do I have the correct implementation for the table I have? Or should I be changing something. I can also send more information/sample data if that would help.
Thank you again!
I just created some tables with your sample data and used the following SQL. Your 3rd 'patient' doesn't match any of the ranges (Age 1, Income $30K)
SELECT tblPatient.PatName, tblPatient.FamInc, tblPatient.Age, tblPatient.Patient,
tblPatientRange.Program, tblPatientRange.MinInc, tblPatientRange.MaxInc, tblPatientRange.MinAge,
tblPatientRange.MaxAge, tblPatientRange.Patient
FROM tblPatient INNER JOIN tblPatientRange ON tblPatient.Patient = tblPatientRange.Patient
WHERE (((tblPatient.FamInc)>=[tblPatientRange]![MinInc] And (tblPatient.FamInc)<=[tblPatientRange]![MaxInc])
AND ((tblPatient.Age)>=[tblPatientRange]![MinAge] And (tblPatient.Age)<=[tblPatientRange]![MaxAge]));

Grouping Data in MS Access 2010 based on multiplication

I am a new user to MS Access.
My table has 2 columns: a column for number of days which goes from 0 to 150+ and a column for principal paid (any number say 858576)
There are over 70000 rows.
Row 1 says 70 days and principal paid as 898956
Row 2 says 68 days and principal paid as 13751
Row 3 says 190 days and principal paid as 397159
Row 4 says 11 days and principal paid as 56978
Row 5 says 29 days and principal paid as 9078910
I want a query to return records from 0-30 days, 30-60 days, 60-90 days, 90-120 days, 120-150 days and 150 above and showing sum of principal against each group mentioned above. Can it be done? If so, how?
If you know the maximum number of your days in the table and criteria for dividing into groups, you could try by using the case:
SELECT
SUM(principal_paid),
days_range
FROM
(
SELECT
principal_paid,
CASE days
WHEN BETWEEN 0 AND 30
THEN '0-30'
WHEN BETWEEN 31 AND 60
THEN '31-60'
WHEN BETWEEN 61 AND 90
THEN '61-90'
WHEN BETWEEN 91 AND 120
THEN '91-120'
WHEN BETWEEN 121 AND 150
THEN '121-150'
ELSE 'over 150'
END AS days_range
FROM
yourtable
)
as T
GROUP BY
days_range

Month wise cumulative total in column

I need cumulative aggregate after each column for my report. I have a dataset with following data samples.
ProductName *Transdate* Quantity
A 21-Nov-13 100
A 1-Nov-13 50
A 1-Dec-13 40
A 1-Jan-13 150
B 11-Nov-13 30
B 2-Dec-13 20
B 13-Dec-13 10
B 12-Jan-13 80
I want a report which look like below. That means Product wise each month total and Cumulative total. I am able to get month wise total value. Only need suggestion for month wise cumulative total.
**
Product Nov'13 Cumulative Total Dec'13 Cumulative Total Jan'13 Cumulative Total
**
A 150 150 40 190 150 340
B 30 30 30 60 80 140
In the proper textbox use RunningValue function: =RunningValue(Fields!Quantity.Value,SUM,"Category1"):
And your report will display values as follows: