473,388 Members | 1,499 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Commissions Query

10
Hello,

I have a query that I used to calculate the monthly, quarterly, semi-annual, annual commissions by agent. Below is the SQL view of this Query.
Expand|Select|Wrap|Line Numbers
  1. SELECT [Client Policy Information].[Policy #], [Client Policy Information].Plan, [Client Policy Information].Placed, [Client Policy Information].Monthly, ([Monthly]-7.65)*[Commission Rate] AS [Monthly Com], [Client Policy Information].Quarterly, ([Quarterly]-22.53)*[Commission Rate] AS [Quarterly Com], [Client Policy Information].[Semi-Annual], ([Semi-Annual]-44.2)*[Commission Rate] AS [Semi-Annual Com], [Client Policy Information].Annual, ([Annual]-85)*[Commission Rate] AS [Annual Com], [Client Policy Information].CTP, ([CTP]*[Commission Rate]) AS [CTP Com]
  2. FROM [Agent Commission Rate] INNER JOIN [Client Policy Information] ON [Agent Commission Rate].AgentID = [Client Policy Information].Agent
  3. WHERE (((Format([Agent]))=[Enter Agent Name]) AND ((Format([Placed],"mm/yyyy")) Between [Start Date (mm/yyyy):] And [End Date (mm/yyyy):]));
The issue I have is that under the PLAN field, we have a UL Product which has a different commission calculation from the rest of the products ([Payment Mode]*[Commission Rate]). How would I go about making it so that if it sees a client purchased a UL product it will calculate the Monthly, Quarterly, Semi-Annual, and Annual commissions using the [Payment Mode]*[Commission Rate] calculations?

Thank you.
Apr 27 '09 #1
9 3912
DonRayner
489 Expert 256MB
Take a look at using the IIF() function in your query. The syntax for using the function is IIF(Criteria,Result True,Result False)

Example
Expand|Select|Wrap|Line Numbers
  1. ([Quarterly]-22.53)*[Commission Rate] AS [Quarterly Com]
would become
Expand|Select|Wrap|Line Numbers
  1. IIF([Client Policy Information].Plan = "YourULProduct",[Payment Mode]*[Commission Rate],([Quarterly]-22.53)*[Commission Rate]) AS [Quarterly Com]
Just a suggestion, but you might want to take a look at your naming convention. If your names were done as QuarterlyCom or Quarterly_Com instead of Quarterly Com then you wouldn't require the [] around the name every time it was used.
Apr 27 '09 #2
menkenk
10
Thanks DonRayner,
I did as you suggested and changed the names to QuarterlyCom, MonthlyCom, etc. to make it easier. I also deleted the [] surrounding them. Im getting a syntax error (missing operator) when I inputted the IIF function you typed down. The SQL view looks like this now.
Expand|Select|Wrap|Line Numbers
  1. SELECT [Client Policy Information].[Policy #], [Client Policy Information].Plan, [Client Policy Information].Agent, [Client Policy Information].Placed, IIF([Client Policy Information].Plan = "UL Protector",[Payment Mode]*[Commission Rate],([Monthly]-7.65)*[Commission Rate] AS MonthlyCom), IIF([Client Policy Information].Plan = "UL Protector",[Payment Mode]*[Commission Rate],([Quarterly]-22.53)*[Commission Rate]) AS QuarterlyCom), IIF([Client Policy Information].Plan = "UL Protector",[Payment Mode]*[Commission Rate],([Semi-Annual]-44.2)*[Commission Rate] AS Semi-AnnualCom), IIF([Client Policy Information].Plan = "UL Protector",[Payment Mode]*[Commission Rate],([Annual]-85)*[Commission Rate] AS AnnualCom), [Client Policy Information].CTP, ([CTP]*[Commission Rate]) AS CTPCom)
  2. FROM [Agent Commission Rate] INNER JOIN [Client Policy Information] ON [Agent Commission Rate].AgentID = [Client Policy Information].Agent
  3. WHERE (((Format([Agent]))=[Enter Agent Name]) AND ((Format([Placed],"mm/yyyy")) Between [Start Date (mm/yyyy):] And [End Date (mm/yyyy):]));
Another thing I realised is that how would I add a second product that goes on the same UL Product commission calculations? Do I just add another "ProductName" next to the "UL Protector"? I'm very new to Access and have only been using it for 3 months now. Sorry if I'm not familiar with many of the functions.
Apr 27 '09 #3
NeoPa
32,556 Expert Mod 16PB
You put the closing parenthesis in the wrong place. It should be :
Expand|Select|Wrap|Line Numbers
  1. ..., IIf([Client Policy Information].Plan = 'UL Protector',[Payment Mode]*[Commission Rate],([Monthly]-7.65)*[Commission Rate]) AS MonthlyCom, ...
Apr 27 '09 #4
DonRayner
489 Expert 256MB
It looks like you have the closing brackets in the wrong spot on your IIF() functions. You should be closing the function before the AS.

You are using
Expand|Select|Wrap|Line Numbers
  1. IIF(IIF([Client Policy Information].Plan = "UL Protector",[Payment Mode]*[Commission Rate],([Monthly]-7.65)*[Commission Rate] AS MonthlyCom)
and it should be
Expand|Select|Wrap|Line Numbers
  1. IIF([Client Policy Information].Plan = "UL Protector",[Payment Mode]*[Commission Rate],([Monthly]-7.65)*[Commission Rate]) AS MonthlyCom
I was under the impression that you only had the one alternative plan, that is why I suggested the IIF as the easiest way to achieve what you were looking for. You can use an OR in your IIF() function but that would require you to edit your query each time you need to add a different "UL Protector"
Apr 27 '09 #5
menkenk
10
Thanks NeoPa & DonRayner,

I got that sorted out, I'm able to save the changes to SQL view. When I run the query, the MonthlyCom, QuarterlyCom, and etc. has #Error where it's supposed to have calculated the commission rate for the UL Protector product. When I open a report based on that Query it says "This expression is typed incorrectly, or it is too complex to be evaluated." Though it calculates the other products' commission rates perfectly fine.

Sorry for the confusion, after I had posted my question I was editing the combo box under Plan and realsed that there were 2 other products which use the same commission calculations as the UL Protector, SUL and UL Plus. I never thought calculating commission would be such a complicated task.
Apr 27 '09 #6
NeoPa
32,556 Expert Mod 16PB
If it gets much more complicated than a simple either/or situation, you may be well advised to determine the results within your query using tables of the data, rather than increasingly complicated IIf() calls.

Logic maintained in tables is generally considered far more easy to maintain than similar logic contained within the code.
Apr 27 '09 #7
menkenk
10
Thanks for the help NeoSpa and DonRaynor,

I figured out my error with your functions. Instead of [Payment Mode] I filled in the corresponding Field I wanted it to calculate. for example [Monthly]*[Commission Rate] for the MonthlyCom, and it worked. My apologies for overcomplicating it. I really appreciate both of your advice.
Apr 27 '09 #8
NeoPa
32,556 Expert Mod 16PB
You're welcome. Glad it works for you :)
Apr 27 '09 #9
DonRayner
489 Expert 256MB
Glad we could help. Good luck with your project.
Apr 27 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: NDS Ltd | last post by:
hi, someone on this group made me a query which worked a treat. i have tried changing it but instead of returning the expected 700 records it returns half a million.. with lots of duplicates. ...
1
by: FRED | last post by:
hi, I have tried but just cannot work it out so i am asking for help.. please :-) I have a query that does this: select all the records in sales that don't have a corresponding record in...
2
by: sal cifone | last post by:
Hello, I am trying to use access vba instead of running an unmatched query. I want to compare two tables and if there is a new sales office in "Commissions" table that is not in the "Conversion"...
2
by: RR | last post by:
I am wondering what tables and relationships I would have to have to keep track of one or several employees commissions per transaction. One tracsaction can have one or several employees work on...
0
by: Syd | last post by:
The problem i have been asked to solve involves calculating commissions for a multi level marketing company. There are several products SAY A B C D and several Associates (or sellers). The...
3
by: Porkapalooza | last post by:
I've inherited a database that had a single flat table holding client and policy information. The policy information included individual fields for estimated commissions (i.e. "Comm 99"; "Comm...
4
by: technobob | last post by:
I have what seems to be a strange situation. I have a table where Sales are recorded. Most of the time there is only a primary salesman involved (Salesman1). When there is a secondary salesman,...
33
by: pollyanna | last post by:
Hi there, I hope this is simple for someone. I always figure things out myself, but I thought it would be real nice to see if anyone else out there thought this was super simple and knew the...
2
by: kishanm | last post by:
I have a table with Salesman' data, incld their assigned commission rate and effective data for that rate. These commission rates change randomly as the salesman move from job to job. when they do...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.