wordpress statistics
  • Today is Monday, February 6, 2012

4 Responses to “MS-Access And Data Processing-2”

  1. Anonymous says:

    What happened to only needing two simple queries? Now I understand what you're trying to achieve I have a much simpler way…

    Use a select query but use the pivot table view.

    First we need to get the Expenses and Revenue transposed using a crosstab query, then add in the calculation for the P+L. In my previous comments I used the query "qry_test_part1". This query transposed the E and R fields.

    In the final query we add the P+L fields by subtracting the Expenses from the Revenue fields. Let's call this qry_test_part2. The SQL for qry_test_part2 is as follows:
    SELECT qry_test_part1.Location, qry_test_part1.Year, qry_test_part1.Month, qry_test_part1.E, qry_test_part1.R, [R]-[E] AS [P+L]
    FROM qry_test_part1
    GROUP BY qry_test_part1.Location, qry_test_part1.Year, qry_test_part1.Month, qry_test_part1.E, qry_test_part1.R, [R]-[E];

    Now, in this query, change the view type to pivot table and drag the fields in as follows:
    Location as a Row field
    Month as a column field
    Year as a Filter field
    Expenses, Revenue and P+L fields as a total field

    You will now find the details laid out exactly as you require. Simply add this query to a command button on click event in vba as follows:
    DoCmd.OpenQuery "qry_test_part2", acViewPivotTable

    That's it, you will find each time a month is added to the table that it's added automatically. Once the year changes, the user needs to simply change the filter option for year.

  2. Can you please present your solution in complete form with SQL Strings of both Queries exactly the same way as you have explained above. The result should match the sample image (2nd image from top on this page) given above.

    The example image that I have presented in the earlier Article as a Question (2nd image from top on this page) needs only two Queries to arrive at that result and I have presented the complete SQL strings of both Queries (Method2_1 and Method2_2) on this page too.

    What is explained and presented further on is how we can refine the procedure to automate and prepare the result in Report form without modifying the Queries every time.

    Regards,

  3. Anonymous says:

    In my earlier comments, you criticized my method for combining two queries to represent the months being displayed as columns. This was to show how I arrived at your sample image. Your response was that it would be necessary to create new queries for each month and you had a solution that only required two steps.

    Looking at your two steps above, they are essentially exactly the same as the solution that I provided? The extra steps you describe above are needed in your solution to provide the end result which is to have all the months in the year as columns. In my last comment I showed the solution to use just two queries to achieve the desired result, with the help of pivottable view. Here are the SQL strings in full…

    The table that holds the data is called tbl_test and I called this query "qry_test_part1"
    TRANSFORM Sum(tbl_test.Amount) AS SumOfAmount
    SELECT tbl_test.Location, tbl_test.Year, tbl_test.Month
    FROM tbl_test
    GROUP BY tbl_test.Location, tbl_test.Year, tbl_test.Month
    PIVOT tbl_test.Type;

    The second query uses qry_test_part1 as it's source table.

    SELECT qry_test_part1.Location, qry_test_part1.Year, qry_test_part1.Month, qry_test_part1.E, qry_test_part1.R, [R]-[E] AS [P+L]
    FROM qry_test_part1
    GROUP BY qry_test_part1.Location, qry_test_part1.Year, qry_test_part1.Month, qry_test_part1.E, qry_test_part1.R, [R]-[E];

    It is this second query that you need to use pivottable view and choose the fields as I explained in my last comments.

    You will find this query provides everything you needed, where each new month and location added will automatically show in the query without any further queries needing to be created, along with the year.

    Regards

  4. I am sorry if you felt offended by my remarks. I accept your example as a simplified version of the solution with PIVOT Table that needs only fewer steps.

    I also accept my ignorance in the usage of PIVOT Table except a few trial runs I did few years back and discarded it from my data processing solutions as it has only limited flexibility in presentation and distribution of information like Reports.

    Regards,

Trackbacks/Pingbacks

  1. Null Query Access | More More Pics

Leave a Reply

You must be logged in to post a comment.