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

How to rank and assign a value?

30
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
Jan 8 '11 #1
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:

Expand|Select|Wrap|Line Numbers
  1. select [Date], [Person], Sum([Machines Sold]) as Sold 
  2. from [tblSales] 
  3. Group by [Date], [Person]
your second query (let's call it Query B) will look like this:

Expand|Select|Wrap|Line Numbers
  1. select [Date], [Person], nz(DSum(1,"[Query A]","[Sold] >" & [Sold]),0) as Rank 
  2. From [Query A]
  3. Where nz(Dsum(1,"[Query A]","[Sold] >" & [Sold]),0) < 6
  4. Group By [Date], [Person]
  5. 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:

Expand|Select|Wrap|Line Numbers
  1. Select [Query B].[Date], [Query B].[Person], [Point Allocation].[Points]
  2. From [Point Allocation] Left join [Query B] on [Query B].[Rank] = [Point Allocation].[Rank]
  3. Group By [Date], [Person], [Points]
  4. 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.
Jan 8 '11 #2
Lisa B
30
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

Expand|Select|Wrap|Line Numbers
  1. Rank: (select [Date], [fkVendeurid], Sum([Machines Sold]) as Sold  
  2. from [Weekly Machines Sales data] 
  3. 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
Jan 9 '11 #3
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])'
Jan 9 '11 #4
Lisa B
30
Am using Access 2010 - am happy to send you the file :P

yes Machines Sold exists - 6th column in [Weekly Machines Sales Data]
Jan 9 '11 #5
Lisa B
30
I have uploaded a zip with the db file in it herehttp://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
Jan 9 '11 #6
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 :-/
Jan 10 '11 #7
Lisa B
30
Unfotunately i can't save as 2003 version and it's using features that don't exist in 2010 :(
Jan 11 '11 #8
Lisa B
30
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

Expand|Select|Wrap|Line Numbers
  1. 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
Jul 1 '11 #9
Lisa B
30
This may help too?


Expand|Select|Wrap|Line Numbers
  1. 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
  2. FROM QrySumOfFacturationEquipe AS AliasSumOfFacturationEquipe;


thank you
Jul 1 '11 #10
I think the nz function works for count. Try:
Expand|Select|Wrap|Line Numbers
  1. Rank: ((Select nz(Count(*),0) FROM QryDistinctFacturationEquipe Where [SumOffacturation]>AliasSumofFacturationEquipe.[SumOffacturation])+1)
Jul 12 '11 #11

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

Similar topics

0
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...
3
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...
0
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...
0
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...
2
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...
4
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...
4
jeffbroodwar
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 : ...
8
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...
1
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...
20
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) { ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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
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...

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.