Results 1 to 6 of 6
  1. #1
    Amigo9 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    4

    Counting Changes

    Hi
    Each month I take a snapshot of my membership database and import this table into access in order to produce a summary report. These tables have fields "Membership No", "Branch", "Name" etc etc etc
    I have been asked to include the last 3 columns below the net change in membership of a branch caused by members changing branches. For example:

    Branch Total Members New Members Resignations Moved Out Moved In Net
    Branch A 500 10 5 1 2 +1
    Branch B 200 5 12 5 4 -1
    Branch C 150 3 3 2 2 0



    I have attached a screenshot of part of the design view of the existing query. The code in the "Moved Out" column works ok but I haven't been able to figure out how to calculate the "Moved To" or "Net"

    I hope this makes sense. Any advice and or assistance gratefully received
    Attached Thumbnails Attached Thumbnails 2015-07-24_110303.png  

  2. #2
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    Move In could just be the swap of the logic from <> to =

    Moved In: Sum(IIF([This MOnth2].[Branch Desc]=[lastmonth2].[branch desc],1,0))

    Net looks like you could count the rows returned in the query.

    Net: Count([This Month].[branch desc])

  3. #3
    Amigo9 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    4
    I tried this but Moved In: Sum(IIF([This MOnth2].[Branch Desc]=[lastmonth2].[branch desc],1,0)) returned the total number of members of the branch not just the movement destinations

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Think for net need to do two aggregate queries then join them.

    Query1
    SELECT [Branch Desc], Sum(IIf(Lapsed Is Null, 1, 0)) AS ThisMonthCount FROM ThisMonth GROUP BY [Branch Desc];

    Query2
    SELECT [Branch Desc], Sum(IIf(Lapsed Is Null, 1, 0)) AS LastMonthCount FROM LastMonth GROUP BY [Branch Desc];

    Query3
    SELECT Query1.[Branch Desc], ThisMonthCount - LastMonthCount AS NetChange FROM Query1 INNER JOIN Query2 ON Query1.Branch = Query2.Branch;

    Query4 shows MoveOut - where ThisMonth.Memb is null, is a loss from last month:
    SELECT ThisMonth.Memb, LastMonth.Memb, LastMonth.BranchDesc FROM ThisMonth RIGHT JOIN LastMonth ON (ThisMonth.BranchDesc = LastMonth.BranchDesc) AND (ThisMonth.Memb = LastMonth.Memb);

    Query5 shows MoveIn - where LastMonth.Memb is null is a gain from last month:
    SELECT ThisMonth.Memb, LastMonth.Memb, ThisMonth.BranchDesc FROM ThisMonth LEFT JOIN LastMonth ON (ThisMonth.Memb = LastMonth.Memb) AND (ThisMonth.BranchDesc = LastMonth.BranchDesc);

    Click image for larger version. 

Name:	Queries.png 
Views:	13 
Size:	47.1 KB 
ID:	21384
    Query4 as an aggregate:
    SELECT Count(LastMonth.Memb) AS CountOut, LastMonth.BranchDesc
    FROM ThisMonth RIGHT JOIN LastMonth ON (ThisMonth.Memb = LastMonth.Memb) AND (ThisMonth.BranchDesc = LastMonth.BranchDesc)
    WHERE (((ThisMonth.Memb) Is Null))
    GROUP BY LastMonth.BranchDesc;

    Query5 as an aggregate:
    SELECT Count(ThisMonth.Memb) AS CountIn, ThisMonth.BranchDesc
    FROM ThisMonth LEFT JOIN LastMonth ON (ThisMonth.BranchDesc = LastMonth.BranchDesc) AND (ThisMonth.Memb = LastMonth.Memb)
    WHERE (((LastMonth.Memb) Is Null))
    GROUP BY ThisMonth.BranchDesc;
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Amigo9 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    4
    Hi

    Thanks June7. There is quite a bit here to take in and to be honest I haven't quite been able to make it work. I suspect this is in part at least because of my data not being completely clean and the example you used was a bit too simple. Over the next couple of days I will clean up my raw data such that the simple model actually fits. Currently your model does not handle new and resigned members independently of members who just change branches. I will remove any new and resigned members from ThisMonth and LastMonth tables and I should be good to go. I will get back to you soon and thank you very much again
    Cheers
    Amigo9

  6. #6
    Amigo9 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    4
    Thanks again. Although your queries did not do exactly what I needed, they were still hugely helpful to me so I could develop the final query myself.

    The final code was:

    SELECT IIf(Len([ThisMonth].[Branch Desc])>14,Left([ThisMonth].[Branch Desc],14) & "...",[ThisMonth].[Branch Desc]) AS [Branch Desc], Query11.[Total Members] AS [Last Month], Sum(IIf([ThisMonth].[Lapsed] Is Null,1,0)) AS [This Month], IIf([This Month]-[Last Month]>0,"+" & [This Month]-[Last Month],[This Month]-[Last Month]) AS Diff, Sum(IIf([ThisMonth].[Join Date]>=startdate() And [ThisMonth].[Join Date]<=enddate() And [ThisMonth].[lapsed] Is Null,1,0)) AS [New Members], Sum(IIf([ThisMonth].[Lapsed Date] Is Not Null And [ThisMonth].[join date]<startdate(),1,0)) AS Resignations, IIf(Nz([query7].[CountIn],0)-Nz([query6].[countout],0)>0,"+" & Nz([query7.countin],0)-Nz([query6.countout],0),Nz([query7.countin],0)-Nz([query6.countout],0)) AS Moves, Sum(IIf([ThisMonth].[Financial]="Financial" And [ThisMonth].[Lapsed] Is Null,1,0)) AS Financials, Sum(IIf([ThisMonth].[Financial]="Unfinancial" And [ThisMonth].[lapsed] Is Null,1,0)) AS Unfinancials, Sum(IIf([ThisMonth].[Financial]="Pending" And [ThisMonth].[lapsed] Is Null,1,0)) AS Pending, Sum(IIf([ThisMonth].[Membership Type Desc]="Suspended Member" And [ThisMonth].[lapsed] Is Null,1,0)) AS Suspended, Round(([Resignations]*100)/([Total members]),2) AS [Churn %]
    FROM ((ThisMonth LEFT JOIN Query6 ON ThisMonth.[Branch Desc] = Query6.[Branch Desc]) LEFT JOIN Query7 ON ThisMonth.[Branch Desc] = Query7.[Branch Desc]) INNER JOIN Query11 ON ThisMonth.[Branch Desc] = Query11.[Branch Desc]
    GROUP BY IIf(Len([ThisMonth].[Branch Desc])>14,Left([ThisMonth].[Branch Desc],14) & "...",[ThisMonth].[Branch Desc]), Query11.[Total Members], IIf(Nz([query7].[CountIn],0)-Nz([query6].[countout],0)>0,"+" & Nz([query7.countin],0)-Nz([query6.countout],0),Nz([query7.countin],0)-Nz([query6.countout],0));

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

Similar Threads

  1. Counting in
    By tngirl in forum Reports
    Replies: 7
    Last Post: 05-24-2013, 11:15 AM
  2. Counting
    By GeirA in forum Queries
    Replies: 7
    Last Post: 02-29-2012, 02:58 PM
  3. Counting Help
    By Jessyx in forum Access
    Replies: 1
    Last Post: 12-03-2011, 01:34 AM
  4. Counting
    By rfs in forum Forms
    Replies: 0
    Last Post: 03-15-2011, 03:20 PM
  5. Counting Records
    By WhiteNite1971 in forum Access
    Replies: 1
    Last Post: 01-22-2011, 06:36 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