Subtraction instead of sum

edited 2:22AM 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 2:22AM
    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 2:22AM
    Thank you for your quick support
    For my second question(about percentage) is there any solution?

Leave a Comment