by 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