Is there a simple way to show percentages instead of values in the pivotgrid?
As in if there are two rows each with an actual value of 2000 and 4000 respectively how can I show the first row as 33.3% and 66.6% etc.
Thanks,Doug
Hi Todor,
Yeah that doesnt really work because I need the percentage to show relative to the slicing of the data.
But I think I have a solution that appears to work. I modified one of the samples for a converter to the following:
public class Converter : IValueConverter{ #region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var cellControl = value as PivotCellControl; var cell = cellControl.Cell as PivotCell;
int column = MainForm.pivotGridReference.DataColumns.IndexOf(cell.DataColumn); int row = MainForm.pivotGridReference.DataRows.IndexOf(cell.DataRow); object result = null;
object cellVal = MainForm.pivotGridReference.DataSource.Result.Cells[row, column].Value; if (cellVal == null || string.IsNullOrEmpty(cellVal.ToString())) cellVal = ""; else { if (column > -1 && row > -1) { result = (MainForm.pivotGridReference.DataSource.Result.Cells[MainForm.pivotGridReference.DataRows.Count - 1, column]).Value;
double cellDouble = Double.Parse(cellVal.ToString()); double resultDouble = Double.Parse(result.ToString()); cellVal = string.Concat(" (", ((cellDouble / resultDouble) * 100).ToString("N2"), " %)"); } } return cellVal; }
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return value; }
#endregion}
It returns a string value that is placed in a seperate textblock in the cell replacing the coloured rectangle from the sample and this seems to work.
So unless someone comes up with a better solution I will go with this.
Hi,
The easy way is to add new filed in you ItemBuy class that will represent a new measure for percent data. You should make estimation for this new measure in your class
Regards
Yes but that just formats whatever value I give it. I want a way to calculate the percentage for me.
Example: if there are two rows with values of 2000 sales and 4000 sales respectively how can I show the first row as 33.3% and 66.6% etc. Not just format it, but calculate it.
Or do I have to do this manually?
Hi Doug,
You can format the value in the cell by applying standard format string to DisplayFormat property when you create new dimension
cubeMetadata.DimensionSettings.Add(new DimensionMetadata(){ SourcePropertyName = "Product", DisplayName = "Product", AutoGenerateField=true, DisplayFormat = "{0} %"});
Todor