Calculated measure: deleting an re-creating

edited April 2015 in FastCube 2
Hi,

There seems to be a a problem (bug??) when I delete a calculated measure and add another one again with the same name, but a different formula / script function. I have the following code to create the calculated measure, which uses a user defined multiplication factor.
with fcxSlice.MeasuresContainer do 
  AddCalcMeasure ('CustomA', 'CustomA', af_Formula, 'CustomFactorA', 'Result := Measures[''TotalFieldName''].CurrentValue * ' + CustomFactor.ToString);

So far it works fine. In my application, the user is allowed to change the factor var CustomFactor : double; to another value as they wish, then click a "recalc" button, which deletes the calculated measure and adds it again, using the following code:
fcxSlice.BeginUpdate;
  
// delete calculated measures
for i := fcxSlice.MeasuresContainer.Count - 1 downto 0 do
  if fcxSlice.MeasuresContainer.Measures[i].AgrFunc = af_Formula then
    fcxSlice.MeasuresContainer.DeleteMeasure(i);

with fcxSlice.MeasuresContainer do 
  AddCalcMeasure ('CustomA', 'CustomA', af_Formula, 'CustomFactorA', 'Result := Measures[''TotalFieldName''].CurrentValue * ' + CustomFactor.ToString);

fcxSlice.EndUpdate;

The loop works fine by itself - it deletes the calculated measure. But when it gets added again with the same field name, caption etc. but a slightly different formula (the variable CustomFactor has changed), it calculates exactly the same values as before, not the updated values with the new CustomFactor.

I could use a different measure name each time or have some other work-around, but the root problem remains. Please could you help me

EDIT: I tried changing the fcxSlice.MeasuresContainer.Measures[].ScriptFunction at run-time, but then the measure becomes completely blank. How can I change the formula of a measure at run-time so it recalculates? I would greatly appreciate any help, thank you.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.