This is a migrated thread and some comments may be shown as answers.

[Solved] Using a calculated column value in another calculated column

4 Answers 173 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael Draisey
Top achievements
Rank 1
Michael Draisey asked on 03 Dec 2009, 11:33 AM
Hi,

This might be a really stupid question but i need to use the value from one calculated column in another calculated column. Is this possible? It's a typical scenario of Product, VAT, Sub Total, Shipping and Total. The Sub-total is calculated, but for Total i need to add Shipping to Sub-Total to make the Total. When I try this it says it cannot find SubTotal (the unique name of the column) in datafields.

Thanks for any help in advance.

Michael

4 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 03 Dec 2009, 12:40 PM
Hello Michael,

You can replace the same expression that is used for finding the 'Sub-Total' in the 'Total' expression instead of using 'Sub-Total' value directly in GridCalculatedColumn.

ASPX:
 
     <telerik:GridCalculatedColumn HeaderText="Sub Total" UniqueName="SubTotal" DataType="System.Double" 
            DataFields="Product, VAT" Expression="{0}+{1}" FooterText="Total : " Aggregate="Sum" /> 
        <telerik:GridCalculatedColumn HeaderText="Total Price" UniqueName="Total" DataType="System.Double" 
            DataFields="Product, VAT, Shipping" Expression="{0}+{1}+{1}" FooterText="Total : " 
            Aggregate="Sum" /> 

-Shinu.
0
Michael Draisey
Top achievements
Rank 1
answered on 03 Dec 2009, 01:17 PM
Hi Shinu,

Good thinking looking at the problem from another angle.

Cheers,

Michael
0
Michael Draisey
Top achievements
Rank 1
answered on 03 Dec 2009, 01:30 PM
Hi Shinu,

Thanks for the help. Just tried it and getting this error - Operator '+' incompatible with operand types 'Double?' and 'Decimal?'

How can I can cast prior to the arithmic operation?

Thanks for the help,

Michael
0
Accepted
Yavor
Telerik team
answered on 08 Dec 2009, 12:54 PM
Hello Michael,

 You must make sure, that the values on which the calculation will be based, are of compatible types. This is what is causing the issue at your end. The other alternative would be to handle the calculations manually, and set the values from the code-behind.

Sincerely yours,
Yavor
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Michael Draisey
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Michael Draisey
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or