Best approach? (1 Viewer)

Gasman

Enthusiastic Amateur
Local time
Today, 02:51
Joined
Sep 21, 2011
Messages
14,265
Hi all,

I am creating a database to replace an Excel workbook I created a short while back.
It tracks commission payments, and at present the % is set.
However I was thinking that would likely change, and have been informed today that it will.
Therefore I need to keep track of the % during a particular period.
I realise that I would need at least
ID - PK
SubmitterID - FK
Rate - %
EffectiveDate -

but unsure on how I would then process this table via queries, or would I need VBA to find what %ge I would need to apply to a trade which is after or before an effective date for the above.

Data will be exported to Excel probably for ease of use by the recipients.
At present each trade shows it's respective commission and whether paid or not.

TIA
 

Isskint

Slowly Developing
Local time
Today, 02:51
Joined
Apr 25, 2012
Messages
1,302
Dmax() function should get you the right % value.
Code:
Dmax("[ID]","[Table]","[EffectiveDate]=<" & [testdate])
will give you the ID. Add that to a Dlookup() for the rate;
Code:
Dlookup("[Rate]","[Table]","[ID]=" & Dmax("[ID]","[Table]","[EffectiveDate]=<" & [testdate]) )
 

Ranman256

Well-known member
Local time
Yesterday, 21:51
Joined
Apr 9, 2015
Messages
4,337
I would use your rate table and run an update query to apply the pct based on Eff Dates.
 

Gasman

Enthusiastic Amateur
Local time
Today, 02:51
Joined
Sep 21, 2011
Messages
14,265
Dmax() function should get you the right % value.
Code:
Dmax("[ID]","[Table]","[EffectiveDate]=<" & [testdate])
will give you the ID. Add that to a Dlookup() for the rate;
Code:
Dlookup("[Rate]","[Table]","[ID]=" & Dmax("[ID]","[Table]","[EffectiveDate]=<" & [testdate]) )

Thank you Isskint
 

Gasman

Enthusiastic Amateur
Local time
Today, 02:51
Joined
Sep 21, 2011
Messages
14,265
I would use your rate table and run an update query to apply the pct based on Eff Dates.

Ranman256,

Are you saying have a field in the Rate table for the percentage?

I have that now, but if the rate changed and I then ran a query or report to report on previous values, it would reflect the current rate and not that at the time of payment.? In excel the values are repeated for each row, and I could change the formula at the correct time, but with the database I am not storing the values and would calculate them each time for query/report etc.

I *thought* that was the correct approach as I have seen it mentioned many times in these forums?

This is a learning experience for me as well as a constructive project.
 

MarkK

bit cruncher
Local time
Yesterday, 18:51
Joined
Mar 17, 2004
Messages
8,181
In excel the values are repeated for each row
If this rate is subject to change, then it may make sense to save it with every object that requires it. For instance, prices are subject to change, so when you make an order or invoice, you look up the current price and then you save that price with the order, and this does not break normalization! Similarly, if you have other time sensitive variables that are required for an object to make sense, it may be the simplest and most reliable approach to save those values as they were at the time the object was created, even if the current value, or even a history of values, are stored elsewhere in your system.

For instance, even if you keep a price history in a Prices table, you should still ALSO store the price of each product in the OrderDetail table.

Hope this helps,
 

Gasman

Enthusiastic Amateur
Local time
Today, 02:51
Joined
Sep 21, 2011
Messages
14,265
If this rate is subject to change, then it may make sense to save it with every object that requires it. For instance, prices are subject to change, so when you make an order or invoice, you look up the current price and then you save that price with the order, and this does not break normalization! Similarly, if you have other time sensitive variables that are required for an object to make sense, it may be the simplest and most reliable approach to save those values as they were at the time the object was created, even if the current value, or even a history of values, are stored elsewhere in your system.

For instance, even if you keep a price history in a Prices table, you should still ALSO store the price of each product in the OrderDetail table.

Hope this helps,

It does thank you.
That approach is certainly easier to implement (for me at least) and would involve less processing when producing reports.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 20:51
Joined
Feb 28, 2001
Messages
27,172
Just to be pedantic... when rates can change dynamically to the point that each sale can have a different rate, then you have two choices for normalization.

One is for cases where a particular rate applies to all sales by a particular sales rep for a particular period. That would be a lookup table case for SalesRepID and SaleDate to pick up the rate.

The other is for cases where any number of special offers apply, such as "Buy item X and pay no interest for 60 months" (or such as that) where sales conditions at the point of the sale determine your rates. There, normalization suggests that the rate applied to the sale is a property associated with the sale itself, not the salesman or date. The rule about where to put things says to put them with the thing on which they depend. Case (1) above goes with a sales-rep/date table. Case (2) goes with the sale itself.

Which is why MarkK's advice is spot-on for this case.
 

Users who are viewing this thread

Top Bottom