Results 1 to 2 of 2
  1. #1
    springboardjg is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2011
    Location
    Milton Keynes
    Posts
    10

    SQL expression to perform a calculation

    Hi



    My SQL query returns the following table.

    Code:
    Springboard_Benchmark | MoMCurrentMonthTotal | MoMPreviousMonthTotal
    Central | 28885 | 27648
    National | 13233457 | 12141305
    Here is the SQL query.

    Code:
    SELECT tbl_SpringboardBenchmarks.Springboard_Benchmark, Sum(qry_MoM_CurrentMonth.MoMCurrentMonth) AS MoMCurrentMonthTotal, Sum(qry_MoM_PreviousMonth.MoMPreviousMonth) AS MoMPreviousMonthTotal
    FROM tbl_SpringboardBenchmarks INNER JOIN 
    (qry_MoM_CurrentMonth INNER JOIN qry_MoM_PreviousMonth ON qry_MoM_CurrentMonth.Average_Grouping = qry_MoM_PreviousMonth.Average_Grouping) 
    ON tbl_SpringboardBenchmarks.Average_Grouping = qry_MoM_CurrentMonth.Average_Grouping
    GROUP BY tbl_SpringboardBenchmarks.Springboard_Benchmark;
    What I want is another column in the table above like this.

    Code:
    Springboard_Benchmark | MoMCurrentMonthTotal | MoMPreviousMonthTotal | %Change
    Central | 28885 | 27648 | 4.47%
    National | 13233457 | 12141305 | 9.00%
    So I need to put the calculation (MoMCurrentMonthTotal)/(MoMPreviousMonthTotal)-1 into my SQL query.

    Becuase I have already used the SUM query I am not sure how to do it without getting an error. Any ideas?


    Many thanks

    James

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    You can try this (totally untested)
    SELECT Benchmark
    ,MoMCurrentMonthTotal
    ,MoMPreviousMonthTotal
    ,(MoMCurrentMonthTotal - MoMPreviousMonthTotal) *100 as PercentChange
    FROM
    (
    SELECT tbl_SpringboardBenchmarks.Springboard_Benchmark as Benchmark
    , Sum(qry_MoM_CurrentMonth.MoMCurrentMonth) AS MoMCurrentMonthTotal
    , Sum(qry_MoM_PreviousMonth.MoMPreviousMonth) AS MoMPreviousMonthTotal
    FROM tbl_SpringboardBenchmarks
    INNER JOIN
    (qry_MoM_CurrentMonth INNER JOIN qry_MoM_PreviousMonth ON qry_MoM_CurrentMonth.Average_Grouping = qry_MoM_PreviousMonth.Average_Grouping)
    ON tbl_SpringboardBenchmarks.Average_Grouping = qry_MoM_CurrentMonth.Average_Grouping
    GROUP BY tbl_SpringboardBenchmarks.Springboard_Benchmark
    );

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

Similar Threads

  1. How to do calculation???
    By latestgood in forum Forms
    Replies: 0
    Last Post: 05-18-2011, 11:11 AM
  2. Query to perform several special operations
    By Allison in forum Queries
    Replies: 4
    Last Post: 05-13-2011, 04:30 PM
  3. Replies: 2
    Last Post: 04-18-2011, 02:46 PM
  4. Perform an operation on multiple files.
    By newuser in forum Access
    Replies: 9
    Last Post: 11-18-2010, 11:21 AM
  5. Replies: 2
    Last Post: 11-18-2009, 06:49 PM

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