Ok, this is a tricky question for the pro's:
My access sheet:
line, id a, id b, val%
----------------
1, a, ac, 0.04
2, a, ac, 0.28
3, a, ac, 0.015
4, a, ac, 0.205
5, a, ac, 0.18
6, a, ac, 0.02
7, a, ac, 0.2
8, a, ax, 0.4
....
50, b, ac , 0.32
....
...
..
each line contains an order to a different supplyer.
val% means percentage of the participarion to deliver one product, so
all the lines with "a, ag" have a sum of 100% = 1, same for "a, ax"
and so on.
query:
now, the sheet sould be grouped by id a and id b (product codes) - no
problem.
But: in the forth row (val%) I want to have the number of lines
needed, until the sum of minimal 0.8 is reached, what means:
id a, id b, lines_needed
-----------------------
a, ac, 4
a, ag, ...
....
"4" because of 0.28 + 0.26 + 0.205 + 0.16, so it counts at first the
biggest numbers.
The sense is, that I will count in our database, how many suppliers
are needed for the delivery of 80 percent of each of our products.
Thank you very much.
Matthias 3 2938
Matthias Haffke wrote: Ok, this is a tricky question for the pro's:
My access sheet:
line, id a, id b, val% ---------------- 1, a, ac, 0.04 2, a, ac, 0.28 3, a, ac, 0.015 4, a, ac, 0.205 5, a, ac, 0.18 6, a, ac, 0.02 7, a, ac, 0.2
8, a, ax, 0.4 ...
50, b, ac , 0.32 ... .. .
each line contains an order to a different supplyer.
val% means percentage of the participarion to deliver one product, so all the lines with "a, ag" have a sum of 100% = 1, same for "a, ax" and so on.
query:
now, the sheet sould be grouped by id a and id b (product codes) - no problem.
But: in the forth row (val%) I want to have the number of lines needed, until the sum of minimal 0.8 is reached, what means:
id a, id b, lines_needed ----------------------- a, ac, 4 a, ag, ... ...
"4" because of 0.28 + 0.26 + 0.205 + 0.16, so it counts at first the biggest numbers.
Want to confuse someone and not get answers? Do what you did.
Use 0.26 and 0.16, figures that aren't used in your demo, to confuse
people.
Also talk about "ag" that isn't used anywhere in your example.
Be sure nobody knows what "line" is...is it a calculated field or a
field and does it have any relelevence except obfuscation?
Then throw in some mutterings 100% but talk about .8.
Then come up with a magic number of 4.
Voila! Instant WTF.
Matthias Haffke wrote: Ok, this is a tricky question for the pro's:
My access sheet:
line, id a, id b, val% ---------------- 1, a, ac, 0.04 2, a, ac, 0.28 3, a, ac, 0.015 4, a, ac, 0.205 5, a, ac, 0.18 6, a, ac, 0.02 7, a, ac, 0.2
8, a, ax, 0.4 ...
50, b, ac , 0.32 ... .. .
each line contains an order to a different supplyer.
val% means percentage of the participarion to deliver one product, so all the lines with "a, ag" have a sum of 100% = 1, same for "a, ax" and so on.
query:
now, the sheet sould be grouped by id a and id b (product codes) - no problem.
But: in the forth row (val%) I want to have the number of lines needed, until the sum of minimal 0.8 is reached, what means:
id a, id b, lines_needed ----------------------- a, ac, 4 a, ag, ... ...
"4" because of 0.28 + 0.26 + 0.205 + 0.16, so it counts at first the biggest numbers.
The sense is, that I will count in our database, how many suppliers are needed for the delivery of 80 percent of each of our products.
Thank you very much.
Matthias
I think I see what you are driving at.
You would be best off if you used a function. In your query, create a
column with something like
LineCount : GetLineCount([ida], [idb], .8)
I'm passing .8. If this number changes, you can change the value in the
query and the function will calc correctly.
Then in the modules create a function called GetCount(). Aircode is:
Public FUnction GetCount(strIDA As string, strIDA2 As String, _
dblDec As Double) As Integer
Dim strSQL As STring
Dim rst As Recordset
Dim dblVal As Double
'select records for the ids
strSQL = "Select number from ... " & _
"Where ida = strIDA and idb = strIDB"
"order by number decending"
set rst = currentdb.openrecordset(strSQL...)
rst.movefirst
Do while not rst.EOF
'add the number from the select
dblVal = dblVal + Number
'increment line count
GetCount = GetCount + 1
'if greater/equal, .8 line count reached
If dblVal >= dblDec Then
exit do
endif
rst.MoveNext
loop
End Function
Salad wrote I think I see what you are driving at.
You would be best off if you used a function. In your query, create a column with something like LineCount : GetLineCount([ida], [idb], .8)
I'm passing .8. If this number changes, you can change the value in the query and the function will calc correctly.
Then in the modules create a function called GetCount(). Aircode is: Public FUnction GetCount(strIDA As string, strIDA2 As String, _ dblDec As Double) As Integer Dim strSQL As STring Dim rst As Recordset Dim dblVal As Double
'select records for the ids strSQL = "Select number from ... " & _ "Where ida = strIDA and idb = strIDB" "order by number decending"
set rst = currentdb.openrecordset(strSQL...) rst.movefirst Do while not rst.EOF 'add the number from the select dblVal = dblVal + Number 'increment line count GetCount = GetCount + 1 'if greater/equal, .8 line count reached If dblVal >= dblDec Then exit do endif rst.MoveNext loop End Function
Thank you very much for the answer. I know, my explication was the
worst I've probably ever made, but it was early and I was tired.
Nevertheless you got it and I solved it. Thank you. The only thing is,
that Access is extremely slow, it takes about one second to generate
five results in the cells and ages for the whole table. Do you have a
solution?
For people who want to use this code later on here the corrected and
working aircode:
Public Function fncGetCountLief(strIDA As String, strIDB As String, _
dblDec As Double) As Integer
Dim strSQL As String
Dim rst As Recordset
Dim dblVal As Double
strSQL = "Select prozlief from [req Lief] " & _
"Where Hauptgruppe='" & strIDA & "' and Warengrp='" & _
strIDB & "' ORDER BY prozlief DESC"
Set rst = CurrentDb.OpenRecordset(strSQL)
rst.MoveFirst
Do While Not rst.EOF
dblVal = dblVal + rst.Fields!prozlief
fncGetCountLief = fncGetCountLief + 1
If dblVal >= dblDec Then
Exit Do
End If
rst.MoveNext
Loop
End Function
Matthias This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: James Butler |
last post by:
Running a CLI script that fopen's a file, parses the lines into an
array, checks the array entries against a few regular expression
qualifiers (i.e. !eregi("bot",$entry)) and dump the good entries...
|
by: Carl |
last post by:
I have a main form with navigation buttons on it and a label showing
for example Record 1 of 15 using recordsetclone on it and eveything
works fine. When I move through the records the record...
|
by: Justin Koivisto |
last post by:
In PHP, I do the following (pseudo code for clarity)...
Query: SELECT distinct(web_contacts.zip) FROM web_contacts WHERE
web_contacts.zip <> ''
Query: SELECT DISTINCT(contacts.zip) FROM contacts...
|
by: Mark |
last post by:
Hi all,
I am currently in the design stages of a database for work. I have come
up with a way to get informaion I need using a union query but was wandering
what effects this will have on...
|
by: Martin Joergensen |
last post by:
Hi,
I have some files which has the following content:
0 0 0 0 0 0
0 1 1 1 1 0
0 1 1 1 1 0
0 1 1 1 1 0
0 1 1 1 1 0
0 0 0 0 0 0
|
by: dotnetnoob |
last post by:
Dim strFacilitFile As String = Func_Facilit(strJobSite)
Dim xTempltDoc As New Xml.XmlDocument
Dim xGpDoc As New Xml.XmlDocument
Dim y As Integer = 0
'Dim intNxtInstNumb As Integer =...
|
by: southoz |
last post by:
Good ay all ,
I'm fairly new to access(a little over 5 weeks now). Since I'v started I have picked up a lot of useful information from forums such as this and in doing so will share that information...
|
by: Simon Gare |
last post by:
Hi,
trying to retrieve postal codes from the db but only want the query to look
at the first 3 digits of the code tried using
(LEFT(dbo.booking_form.COLL_POST_CODE),3) but that doesn't work. I...
|
by: fel |
last post by:
does anybody know of any *web* query builder in PHP, something like
the Access query builder, or similar, done in PHP or similar?
I've looked for it trough the net, but nothing is colse to what I...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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...
|
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: 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...
|
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,...
| |