Calculated Measur with %

Discussion forum for PivotCube VCL users. Common questions. Bug and problem reports

Moderator: Alex Zencovich

Calculated Measur with %

Postby Siegmar Gieseler » Thu Jul 13, 2006 9:35 pm

I am using the following formula to create a Calculated Measure:

begin
Result = Valor[VALUE] / ( Valor[ROW] + Valor[COLUMN] - Valor[VALUE] ) * 100;
end;

It works, but now I have a cube lwith 2 dimensions for rows like this:

A1
B1
B2
B3
A2
C1
C2
C3

I would like to calculate a % like B1/A1, B2/A1, B3/A1 and C1/A2, C2/A2, C3/A2.
Is it possible ?

Thanks
Siegmar Gieseler
User
 
Posts: 9
Joined: Mon Jun 19, 2006 2:49 am

Postby AlexZencovich » Fri Jul 14, 2006 5:17 am

Sorry, it is impossible in current (7.x) version.
Best regards,

Alex Zencovich
-------------------------------------------------------------------------------------------------------------------------------------------
www.pivotcube.com - OLAP solution for Delphi, C++ Builder and ActiveX environment
AlexZencovich
Site Admin
 
Posts: 580
Joined: Sun Jun 18, 2006 10:09 am

Postby Guillaumep » Tue Jul 18, 2006 11:22 am

Hello,
You can do it with calcultated measure assuming AliasName ends with PourcentGroupByRow for example.

Connect the TPivotGrid.OnGetCellValue to this method :

procedure TForm1.PivotGrid1GetCellValue(Sender: TObject; X, Y, RowIndex,
ColumnIndex, MeasureIndex, ViewIndex: Integer; var Value: Double;
var CellString: String; Cell: TpvCellDrawing);
var
tmpMeasure: TMapMeasure;

function pivotMapGetOwnerPourcentValue(AMap: TPivotMap; ARowIndex, AColIndex, AMeasureIndex: Integer): Double;
var
tmpCell: ICell;
value, parentValue: Double;
begin
if ARowIndex = -1 then
begin
Result := 100;
Exit;
end;

Result := 0;
tmpCell := AMap.RowCells[ARowIndex];
if (tmpCell <> nil) and (tmpCell.Owner <> nil) then
begin
value := AMap.Cells[AColIndex, ARowIndex, AMeasureIndex, mvtValue];
tmpCell := tmpCell.Owner;

if tmpCell.Level = 0 then
parentValue := AMap.ColumnTotal[AColIndex, AMeasureIndex, mvtValue]
else
parentValue := AMap.Cells[AColIndex, tmpCell.Position, AMeasureIndex, mvtValue];

if parentValue <> 0 then Result := (value / parentValue) * 100;
end;
end;
begin
tmpMeasure := PivotMap.MeasureByIndex[MeasureIndex];
if AnsiEndsStr(AnsiUpperCase('PourcentGroupByRow'), AnsiUpperCase(tmpMeasure.AliasName)) then
Value := pivotMapGetOwnerPourcentValue(PivotMap, RowIndex, ColumnIndex, MeasureIndex);
end;

Hope this can help...

Guillaume
Guillaumep
User
 
Posts: 13
Joined: Tue Jul 18, 2006 11:19 am


Return to PivotCube VCL

Who is online

Users browsing this forum: No registered users and 7 guests

cron