473,408 Members | 1,753 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,408 software developers and data experts.

Max function

Dear all,

I have to calculate the highest rebate percentage during 3 meeting round. The rebates differ almost every round (can be higher, can be lower)

I want to know how I can calculate the highest rebate without showing the other lower values.

E.g.
Round 1 Round 2 Round 3
Product 1: 0,05 0,03 0,07
Product 2: 0,02 0,03 0,01

In this case the outcome (by use of query) should be:

Product 1: 0,07
Product 2: 0,03
Nov 6 '06 #1
11 3018
VALIS
21
Dear all,

I have to calculate the highest rebate percentage during 3 meeting round. The rebates differ almost every round (can be higher, can be lower)

I want to know how I can calculate the highest rebate without showing the other lower values.

E.g.
Round 1 Round 2 Round 3
Product 1: 0,05 0,03 0,07
Product 2: 0,02 0,03 0,01

In this case the outcome (by use of query) should be:

Product 1: 0,07
Product 2: 0,03
A couple of questions
If two rounds have the same result for the rebate do you need to record this in the result?
Are there going to be move rounds?

If there are only 3 you could use a nested IIF statement to get the result in a Query.

Expand|Select|Wrap|Line Numbers
  1. MaxRebate:IIF(AND([Round 1]>[Round 2],[Round 1]>[Round 3]),[Round 1],IIF(AND(([Round 2]>[Round 1],[Round 2]>[Round 3]),[Round 2],[Round 3])
Any more rounds and it would get messy this way
Nov 6 '06 #2
It doesn't matter if mutiple rebates are the same. As long the highest rebate is taken. And 3 is the maximum rounds.

I used your formula, but it gives an error:

"The expression your entered has an invalid (.) dot or ! operator or invalid parentheses."

I have the english version, but even changing comma's for dot comma (;) does not work.

Also should I put the formula is a new field (in the query) or can I put this as a criteria of one of the rebate levels.

This is the sql of my query

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCTROW Mothercompany.Mothercompanyname, Rebates.[Rebate level 1], Rebates.[Rebate level 2], Rebates.[Rebate level 3]
  2. FROM Mothercompany INNER JOIN Rebates ON Mothercompany.Mothercompanycode = Rebates.Mothercompanycode;
Maybe this will help you resolve my problem...

Thanks for your help!
Nov 6 '06 #3
NeoPa
32,556 Expert Mod 16PB
Try :-
Expand|Select|Wrap|Line Numbers
  1. MaxRebate:IIf([Round 1]>IIf([Round 2]>[Round 3],[Round 2],[Round 3]),[Round 1],IIf([Round 2]>[Round 3],[Round 2],[Round 3]))
instead.
The AND() function isn't available within SQL like that.
Nov 6 '06 #4
I did almost the same as you.

Expand|Select|Wrap|Line Numbers
  1. IIf([Rebate level 1]>=[Rebate level 2];[Rebate level 1];IIf([Rebate level 2]>=[Rebate level 3];[Rebate level 2];[Rebate level 3]))
But for some weird reason, it does not give all of the highest rebates...
It only gives around 40% of all records... Now I have no clue why
Nov 7 '06 #5
NeoPa
32,556 Expert Mod 16PB
Try doing the same as me - see what happens then?
Nov 7 '06 #6
Unfortunately still the same. I don't get all records.
Although I find it peculiar that the query returns more records if I put the formula @ the criteria for round 2 or 3 compared to round 1.

Also adding "MaxRebate:" to the formula gives me an error, but the formula works without... Any idea why?
Nov 8 '06 #7
NeoPa
32,556 Expert Mod 16PB
Yes.
When I posted the code, I had no idea where you intended to use it (as it happens - in the Criteria property) so I formulated it as a field displayed in a query.
MaxRebate: just names the output of the column for clarity.

If you post exactly what you used in your criteria field (AND which field it is used in) - I'll check it over for you.
Nov 8 '06 #8
This is my query:
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCTROW Rebates.ContractSupplier, Rebates.Product, Rebates.[Rebate level 1], Rebates.[Rebate level 2], Rebates.[Rebate level 3]
CODE]IIf([Rebate level 1]>=[Rebate level 2];[Rebate level 1];IIf([Rebate level 2]>=[Rebate level 3];[Rebate level 2];[Rebate level 3]))[/code]

- When I put the formula in rebate level 1, 13 or 56 records are found;
- When I put the formula in rebate level 2, 14 of 56 records are found;
- When I put the formula in rebate level 3, 41 of 56 records are found.

Some rebate levels are the same. But that does not matter for the result. As long as the maximum is showed.

Thanks for your help! :-)
Nov 8 '06 #9
NeoPa
32,556 Expert Mod 16PB
I'm getting more and more confused.
You keep posting code in here which is impossible (the ';' characters won't work in any of my tests).
Also, you talk about setting this code in your criteria field(s), yet when you post the SQL there is no WHERE clause for me to look through (which would be created if you had any criteria there at all).
I need you to copy and paste (not type out again as that introduces typos) the SQL that needs looking at.
I would like to help, but it is impossible unless you give the info requested in the form requested.
Nov 8 '06 #10
SELECT DISTINCTROW Rebates.ContractSupplier, Rebates.[Rebate level 1], Rebates.[Rebate level 2], Rebates.[Rebate level 3]
FROM Rebates
WHERE (((Rebates.[Rebate level 3])=IIf([Rebate level 1]>=[Rebate level 2],[Rebate level 1],IIf([Rebate level 2]>=[Rebate level 3],[Rebate level 2],[Rebate level 3]))));


Comma's don't work with my english/american version of Access. Therefore you should substitute the dot-comma's ( ; ) with comma's. I reckon it will work then.
Nov 10 '06 #11
NeoPa
32,556 Expert Mod 16PB
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCTROW Rebates.ContractSupplier, IIf([Rebate level 1]>=[Rebate level 2],[Rebate level 1],IIf([Rebate level 2]>=[Rebate level 3],[Rebate level 2],[Rebate level 3])) AS MaxRebate
  2. FROM Rebates;
I don't understand what you're saying about the 'semi-colon's ( ; ) - but that shouldn't be important.
If this code doesn't work then feel free to swap the commas out :s
Nov 11 '06 #12

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

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
5
by: phil_gg04 | last post by:
Dear Javascript Experts, Opera seems to have different ideas about the visibility of Javascript functions than other browsers. For example, if I have this code: if (1==2) { function...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
2
by: sushil | last post by:
+1 #include<stdio.h> +2 #include <stdlib.h> +3 typedef struct +4 { +5 unsigned int PID; +6 unsigned int CID; +7 } T_ID; +8 +9 typedef unsigned int (*T_HANDLER)(void); +10
8
by: Olov Johansson | last post by:
I just found out that JavaScript 1.5 (I tested this with Firefox 1.0.7 and Konqueror 3.5) has support not only for standard function definitions, function expressions (lambdas) and Function...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
4
by: alex | last post by:
I am so confused with these three concept,who can explained it?thanks so much? e.g. var f= new Function("x", "y", "return x * y"); function f(x,y){ return x*y } var f=function(x,y){
7
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.