Hello, I've been trawling the web trying to find how to build the expression to rank how many machines an individual has sold by date and to assign points for the ranks - so he who sold the most 6points, 2nd 4 points, 3rd 3 points, 4th 2 points 5th 1 point.
This is how my query is set out
Thank you
10 3939
i'd imagine the sales are stored in a table somewhere?
in that case there are first two questions you need to know in order to solve this: what to do in the case of a tie and what to do in the case that all but 4 or less people sold zero machines.
your question is similar to generating praeto charts, which in general, you will have to set up two queries for those. Because you want to add the extra dimension of points, you will need two queries and a table: however it will look cleaner with three queries and a table so that's what I'm going to do here.
the first will just be a sum query (let's call it query A), like this: - select [Date], [Person], Sum([Machines Sold]) as Sold
-
from [tblSales]
-
Group by [Date], [Person]
your second query (let's call it Query B) will look like this: - select [Date], [Person], nz(DSum(1,"[Query A]","[Sold] >" & [Sold]),0) as Rank
-
From [Query A]
-
Where nz(Dsum(1,"[Query A]","[Sold] >" & [Sold]),0) < 6
-
Group By [Date], [Person]
-
Order by Rank
now the '[Sold] >" & [Sold]' may need to be a '[Sold] >=" & [Sold]' depending on how you want to treat ties. I recommend not doing this, as it gets tricky.
also, you may need to make a small "point allocation" table with two integer fields: rank and points. depending on how you want to treat ties, your "point allocation" table may need to start at rank 0 (in the case of > start with rank 0 in the case of >= start with rank 1)
in addition, you will need a third query that would look like this: - Select [Query B].[Date], [Query B].[Person], [Point Allocation].[Points]
-
From [Point Allocation] Left join [Query B] on [Query B].[Rank] = [Point Allocation].[Rank]
-
Group By [Date], [Person], [Points]
-
Where isnull([Date]) = False
here, the left join may need to be an inner join depending on how you want to handle situations when all but 4 or less have sold 0.
Thank you for your quick reply
Sales are stored in the table [Weekly Machines Sales Data]
the people are Vendeurs
When i adapt your first query with - Rank: (select [Date], [fkVendeurid], Sum([Machines Sold]) as Sold
-
from [Weekly Machines Sales data]
-
Group by [Date], [fkVendeurid])
I'm getting an error
You have written a subquery that can return more than onefield without using the EXISTS reserverd word in the main query's FROM clause. Revise the SELECT statement of the subquery to request only one field
(oo this is giving me a headache!) - thanks so much for the help
what version of access are you using? that's not an error i've ever seen so i might be using an older/newer version than you?
also, your [Weekly Machines Sales data] table, does it have a [Machines Sold] field? I don't see it in the picture, and that would cause an error if it didn't have that field.
If not and each entry counts as one sale, try changing the 'Sum([Machines Sold])' to 'Count([fkVendeurid])'
Am using Access 2010 - am happy to send you the file :P
yes Machines Sold exists - 6th column in [Weekly Machines Sales Data]
I have uploaded a zip with the db file in it here http://cid-4490afdc094900ec.skydrive...DC094900EC!368
I'm aiming towards having a ranking with value assigned for most machines sold and largest margin for each seller and for each team(equipe) for any given date period
Thanks again
Hmm.
I'm using Access 2003. I wouldn't think the SQL syntax would be so vastly different, but apparantly it is.
it works fine in my recreation, and I can't open yours since I'm using 2003 :-/
Unfotunately i can't save as 2003 version and it's using features that don't exist in 2010 :(
Hi again
I am successfully ranking several queries now, however, I don't want it to rank if the value is 0, I want it to return a zero ranking
This is my expression - Rank: ((Select Count(*) FROM QryDistinctFacturationEquipe Where [SumOffacturation]>AliasSumofFacturationEquipe.[SumOffacturation])+1)
So, what do I add to tell it to return a 0 rank if the SumOffacturation=0?
thank you
This may help too? - SELECT AliasSumOfFacturationEquipe.SumOfFacturation, AliasSumOfFacturationEquipe.Equipe, ((Select Count(*) FROM QryDistinctFacturationEquipe Where [SumOffacturation]>AliasSumofFacturationEquipe.[SumOffacturation])+1) AS Rank, IIf([rank]=1,6,IIf([rank]=2,4,IIf([rank]=3,3,IIf([rank]=4,2,IIf([rank]=5,1,0))))) AS Points
-
FROM QrySumOfFacturationEquipe AS AliasSumOfFacturationEquipe;
thank you
I think the nz function works for count. Try: - Rank: ((Select nz(Count(*),0) FROM QryDistinctFacturationEquipe Where [SumOffacturation]>AliasSumofFacturationEquipe.[SumOffacturation])+1)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Cindy X |
last post by:
I have a drop-down as usercontrol.
In the user control's Page_Init , the drop down gets populated.
The SelectedItem.Text is retrived using property get
The Value of the drop-down is assigned...
|
by: astro |
last post by:
this must be obvious and i'm missing it...............
i want to have 4 checkboxes in a groupbox - box1 value = 1, box2 = 2, box3 =
4, box4 = 8
these ctrls are not bound...I want to assign...
|
by: hzgt9b |
last post by:
Using VB.NET 2003,
I get the following error when I assign a value to my WMP player's URL
attribute:
player.URL = "C:\Audio\..\Content_IRB\Audio\Audio_IRB.0.wav"
Err Object contents...
|
by: dd |
last post by:
Hi, I have the following code and want to assign value to a 3D arrays
and print it out. But it seems that the value 1 hasn't been assigned to
that array.
Could anyone help me out? Thank you very...
|
by: |
last post by:
Hi everyone,
I have a form with a combo box on it. When you select a value (a PO#) from
the combo box, the bound field is the indexID of the selected PO. On the
same form, I have a text box...
|
by: jed |
last post by:
I have tried
sqlCommand1.Parameters.Value = float.Parse(textBox1.Text);
but the debugger says that it cant see the parameter
How can i gain access to the parameter in C# EXpress.thanks in...
|
by: jeffbroodwar |
last post by:
Hello, i have a problem about assigning a char value to a byte... please check the code below :
========================================================
Scenario # 1 : This code doesn't work :
...
|
by: getmeidea |
last post by:
Hi,
I am using JDK 1.5.
I have a program like this. Here i am directly assigning value to one object.
It does'nt give me any compile time or run time error. In java we dont have access to any...
|
by: balakrishnan.dinesh |
last post by:
Hi frndz ,
I want to assgin value to <input type=file, without
clicking browse button ,
And i know that it is readonly , But how it is possible in Firfox
browsers ?..
Is there any...
|
by: Shalini Bhalla |
last post by:
i am not able to assign values ,can any one tell me whats wrong ....
<script>
function changeMySrc(nm,act)
{
alert("hi"+ nm );
if(act == 1)
{
...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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,...
|
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...
| |