문제

Consider my following XtraReport

enter image description here

It generates following output when previewed.

enter image description here

Notice the sum of Total marks in the report footer i.e 125. My Question is: How will I calculate the sum of the only fields where result is p. Thus in this case sum of TotalMarks should be 75.

도움이 되었습니까?

해결책

I found its solution by adding a calcultedfield and assigning

Iif([Result]='P',[TotalMarks],0 )

in expression editor.

다른 팁

As far as I know, I would do it manually via the summary label's BeforePrint event. Calculate the required sum with code, and assign the result to the Text property of the label. This works well if you can explicitly access your datasource in the report (for example if you use IList datasource).

private void sumLabel_BeforePrint(object sender, BeforeEventArgs e) {
  XRLabel lbl = sender as XRLabel;
  if (lbl == null) return;
  int sum = myList.Where(item => item.Result == "P").Sum(item => item.TotalMarks);
  lbl.Text = sum;
}

With another manual solution you could summarize the required values during printing the report by handling the Detail band's BeforePrint event, and then assign the calculated sum to the sum label in its BeforePrint event similarily to above. This approach is more efficient and flexible for more complicated datasources.

int currentSum = 0;
private void Detail_BeforePrint(object sender, BeforeEventArgs e) {
  var currentRow = GetCurrentRow() as MyData;
  if (currentRow == null) return;
  if (currentRow.Result == "P")
    currentSum += currentRow.TotalMarks;
}

private void sumLabel_BeforePrint(object sender, BeforeEventArgs e) {
  XRLabel lbl = sender as XRLabel;
  if (lbl == null) return;      
  lbl.Text = currentSum;
  // invalidate the currentSum for the case of any further report pringing process
  currentSum = 0;
}

Unfortunately I don't know about any solution which could be applied purely by designer. Hope it helps.

Though kashif Solution is not show the Sum value,but main logic is there. If you want Sum use Sum() function :-

Sum(Iif([Result]='P',[TotalMarks],0 ))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top