Hi, I have a table Hazard that I want to create an increment row value in, using the formula (MAX(Hazard[Hazard Number]) + 1).
Hazard rows are Keyed to the table Machine. I want to have these integer increases tied to the specific machine in Hazard.
I’m a bit puzzled about which function to use. I basically want to select rows tied to a particular machine and increment the value in the Hazard Number field each time a new hazard is added, but each machine ID has its own list of hazards.
You want Hazard Count in a Machine view or Hazard View?
I assumed you’d want it in a Machine view, in which case, the number of related hazards to the machine row you select shows exactly those hazards related to the row’s machine ID.
Count is automatically incremented as soon as you add a new hazard.
When I’m on the Add Hazard form, I want to have a counter that counts how many Hazard rows already exist for the selected Machine and then increment it to generate the Hazard Number.
Hazards belong to Machines, they are 1 to many where 1 Machine has many Hazards.
So the formula I need must be something like (in logic):
When adding a new Hazard row to the Hazard table against a related Machine >> Count the number of rows already in Hazard, where Machine IDs are the same as the currently selected Machine >> Increment by 1 >> Load the resultant value in Hazard Number field in the Hazard table.
but this gives me the problem that editing existing ones gives them the incorrect number. How do I test if it’s a new one or an existing one and only add 1 for the new ones please?
thanks for your help
James
EDIT
Oh dear, this is obviously more complicated than I realised, if there are no records, it loads the Counter as zero from this formula, but I need the first one to be 1 and you can’t apparently put an initial value in a formula-driven virtual column.
There must be an elegant solution to this. Basically I need a counter that starts at 1 and then each time a new record is added, makes them 2,3,4, etc. I can see that potentially another issue is what happens if one gets deleted. The initial numbering sequence needs to stay in place if that happens.
It seems like this is something that is actually pretty complex.
EDIT
I’m also hitting the problem that it doesn’t write these out on a template with each value, it just stores them all with the most recent Count value.