Results 1 to 11 of 11
  1. #1
    kestefon is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    108

    % Variance Section in Report

    Hi,



    I'm trying to create a report that has three sections. Section 1 = Planned Cost; Section 2 = Actual Cost; and Section 3 = % Variance. I was able to build the first two sections easily with my query, but I'm having some trouble with the % variance part. Would I have to build that into the query itself, or is there an easier way to do it within the Access report fields?

    Below I've included a mock-up (drawn in Excel) of what I'd like the Access report to look like.

    Click image for larger version. 

Name:	ReportLayout.png 
Views:	3 
Size:	49.0 KB 
ID:	16765

    Also, for reference, this is what the query used for my report looks like. Note: The original raw data looks a bit different, but I used a crosstab query in order to get the months of the year to appear horizontally as fields. (That's how I need my final report to look.)
    Click image for larger version. 

Name:	TableSample.png 
Views:	3 
Size:	45.5 KB 
ID:	16766

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    What have you done so far in constructing report? How are you creating sections in report? Are you using subreports? Or Grouping & Sorting? I am not sure which will be easiest.

    Building variance calcs into query would probably involve a UNION query.
    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.

  3. #3
    kestefon is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    108
    I'm using groups within a single report, based on a single query (see second screenshot in original post for a sample of how my query is structured). The report is grouped by: DataType, Product.

    I was thinking of doing a Union as well, but wanted to confirm whether that was the easiest approach. What would the query look like for calculating % variance?

    Thanks!

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    An aggregate query based on raw data (assuming Planned and Billed records are in same dataset) to calculate variance would use expression like:

    (Sum(IIf([DataType]="Planned",[data],0) - Sum(IIf([DataType]="Billed",[data],0)) / Sum(IIf([DataType]="Billed",[data],0) * 100 As Variance

    Apply group criteria for Brand, Market, YearMo.
    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
    kestefon is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    108
    Hmm, it doesn't seem to be working for me. The result is just -100...

    Code:
    SELECT DataType, Market, Brand, Period, ((sum(IIf([DataType] = "Planned", [Data],0)) / sum(IIf([DataType]  = "Billed", [Data],0)))-1)*100 AS Variance
    FROM RawData
    GROUP BY DataType, Market, Brand, Period;

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Is your field actually named Data? Are your data values actually "Planned" and "Billed"?
    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.

  7. #7
    kestefon is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    108
    My table names are slightly different, but I adjusted them accordingly. Here's a sample of how the raw data table is laid out.
    Click image for larger version. 

Name:	TableScreenshot.png 
Views:	3 
Size:	64.1 KB 
ID:	16771

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Does it work with the correct field name? You should have seen popup input prompt because of incorrect name.

    Do not select DataType field and do not include DataType in the GROUP BY clause.
    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.

  9. #9
    kestefon is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    108
    Ah, that's it! I removed DataType and now it works. Thanks!

  10. #10
    kestefon is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    108
    One more quick question...how would I go about removing the Div/0 records? I tried doing "WHERE Variance <> "#Div/0", but that didn't work. Is there some sort of error function I can use in the WHERE clause?

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    This will not return the error but also probably not a desired result.

    Sum(IIf([DataType] = "Billed", [Actual],1))

    I am not sure how to handle situation where there is no Billed data.

    Try:

    IIf(Sum(IIf([DataType]="Billed", [Actual], 0))=0, Null, Sum(IIf([DataType] = "Billed", [Actual],0)))

    If that won't work, might need to do separate aggregate queries for Planned and Billed then join those queries. Then do IIf calc in that query.

    IIf(IsNull(SumOfBilled), 0, SumOfPlanned / Nz(SumOfBilled,1) -1) * 100
    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.

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

Similar Threads

  1. Columns in Report Detail Section only
    By gg80 in forum Reports
    Replies: 10
    Last Post: 08-03-2014, 07:41 PM
  2. Replies: 2
    Last Post: 01-09-2014, 07:24 PM
  3. Replies: 6
    Last Post: 03-26-2013, 12:17 PM
  4. Help with Variance report.
    By Ray67 in forum Reports
    Replies: 0
    Last Post: 07-10-2012, 08:55 PM
  5. Data variance calculation report
    By O2BSmart in forum Access
    Replies: 4
    Last Post: 08-10-2010, 09:35 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