Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8482161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:45:12+00:00 2026-06-10T19:45:12+00:00

Im trying to code a calculation in Access that involves the SUM of some

  • 0

Im trying to code a calculation in Access that involves the SUM of some values plus the result of an IF statement.

Here is a table of the kind of data I’m dealing with (from ‘CostBaseQuery)

CompanyName Year    AssetName  DatapointID  Datapointname                DatapointValue
CompanyA    2011    AssetA     4025         Active operated wells           129
CompanyA    2011    AssetA     4058         API gravity of oil              38.5563255
CompanyA    2011    AssetA     4032         Number of gas lift wells        70
CompanyA    2011    AssetA     4033         Number of wells with ESPs       0
CompanyA    2011    AssetA     4036         Wells with CO2 production       25
CompanyA    2011    AssetA     4035         Wells with H2S production       9
CompanyA    2011    AssetA     4038         Wells with high pressure        0
CompanyA    2011    AssetA     4037         Wells with high temperature     0
CompanyA    2011    AssetA     4034         Wells with scale production     42
CompanyA    2011    AssetA     4039         Wells with wax                  0

The calculation needs to SUM(DatapointValue) WHERE DatapointID IN (4032,4033,4035,4036,4037,4038,4039)

PLUS the value returned from the IF Statement

IF (API gravity of oil <=5 or >20, Use the value of ActiveOperatedWells, Else 0)

I tried to use the following method to code the calculation but it outputs data on each iteration of the SUM rather than carrying out the SUM calculation and THEN the IF statement.

SELECT qb1.CompanyName, qb1.AssetName, qb1.Year, 
(SUM(qb1.DatapointValue) 
+ IIF(qb2.DatapointValue>=5, 
       IIF(qb2.DatapointValue<20, qb3.DatapointValue, 0), 0)) 
AS NumberOfWellCompletions

FROM (CostBaseQuery AS qb1 
     INNER JOIN CostBaseQuery AS qb2 
          ON qb1.CompanyYearAssetID=qb2.CompanyYearAssetID) 
     INNER JOIN CostBaseQuery AS qb3 
          ON qb1.CompanyYearAssetID=qb3.CompanyYearAssetID

WHERE qb1.DatapointID IN (4032,4033,3036,4035,4038,4037,4034,4039)
AND qb2.DatapointID=4058 AND qb3.DatapointID=4025

GROUP BY qb1.CompanyName, qb1.AssetName, qb1.Year, 
qb1.DatapointValue, qb2.DatapointValue, qb3.DatapointValue

Any help would be much appreciated and I hope this makes more sense than my previous rambling!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:45:13+00:00Added an answer on June 10, 2026 at 7:45 pm
    SUM(qb1.DatapointValue + IIF(ab2.DatapointValue <=5 AND qb2.DatapointValue > 20, qb3.DatapointValue, 0)) as NumberOfWellCompletions
    ...
    
    GROUP BY qb1.CompanyName, qb1.AssetName, qb1.Year
    

    You can simplify your SUM (well, not clear about what you want to sum, but you may have a problem of brackets)

    You must be clear if you need to check <= 5 or >=5 (difference between text and code in your question)

    You must change your GROUP BY

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right, I'm trying to make an app that has a calculation that involves a
Here's the sample C code that I am trying to accelerate using SSE, the
I am trying to code an application that monitors sms messages. I want to
I m trying write code that after reset set up rrpmax as 3000. It
I am trying to code a widget that collates Tweets from multiple sources as
I have some code where I am trying to use variables in a tabpage.
I'm trying to set up a cube calculation. My current remit is that I
I'm trying to implement a very basic eigenface calculation in Matlab. It kind of
I am trying to improve an existing javascript levenstein distance calculation source code to
Im trying to create a calculation in Access through the use of queries. At

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.