Subtraction instead of sum

edited 6:53AM in FastCube
Good evening
I need to subtract totals instead of sum them(see attachment).
I use following function to make the job

function Subtract(s:string):Variant;
var i : integer;
begin
result := 0;
for i := 0 to Measures.RecordCount - 1 do
begin
if Measures.detailValue(i,s) > 0 then
begin
if Measures.detailValue(i,'YearRec') = '2014' then
result := result + Measures.detailValue(i,s)
else
if Dimensions.IsTotalByRow and not Dimensions.IsTotalByCol then
result := result + Measures.detailValue(i,s)
else
result := result - Measures.detailValue(i,s);
end;
end;
end;

I call above function for each field like this

procedure Measure_1OnGetTotalValue(var Result: Variant);
begin
result := Subtract('Total Overnights');
end;

The problem is that is to slow.
Is there any recommendation?

The other problem is that I cannot find a solution to add another column, in totals, with percentage
Is there any solution fo this?

Many thnaks in advance
Nikos Andrianakis

Comments

  • edited 6:53AM
    Hi.

    You can create simple measure based on filed 'Total Overnights' (with name 'to_Fantome') and hide it.
    Then create calculation measure (with name 'TO'), set type 'calculation' and use script:
    procedure TOOnGetValue(var Result: Variant);
    var
      v1, v2: variant;
    begin
      if Dimensions.IsTotalByCol and (measures.XLevel = -1) then
      begin
        v1 := measures['to_Fantome'].GetValueWithColDimValues(['2013']);
        v2 := measures['to_Fantome'].GetValueWithColDimValues(['2014']);
        result := (v2 - v1);
      end
      else
        result := measures['to_Fantome'].CurrentValue;
    end;
    

    Also you can check v1 and v2 for assigned value:
    (vartype(v1)<>0)
    (vartype(v2)<>0)

    Best regards,
    Oleg Pryalkov.
  • edited 6:53AM
    Thank you for your quick support
    For my second question(about percentage) is there any solution?

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.