Calculated measures

Posted by: danreber on 3 August 2017, 3:48 pm EST

  • Posted 3 August 2017, 3:48 pm EST

    If ddAnalysis is passed unbound data, can calculated measures be added with the expression evaluated by the control?

  • Replied 3 August 2017, 3:48 pm EST


    Thanks for your patience on this. I was able to construct a schema that shows how you can do this. You must first define the calculated field in the 'QueryFields' collection. Once it's defined here, you would then reference the field from your actual measure's definition. Notice below:

        <QueryFields listcount="23">
            <Item id="0" Name="CategoryName"/>
            <Item id="1" Name="ProductName"/>
            <Item id="2" Name="OrderDate"/>
            <Item id="26" Name="OrderDate_Day">
                <Expression Type="Integer">=Day(Fields!OrderDate.Value)</Expression>
    <b>        <Item id="27" Name="<font color="#ff0000">TwiceTheFreight</font>">
                <Expression Type="Float">=Fields!Freight.Value*2</Expression>
        <dimensions listcount="7">

            <Item id="0">
                <fields listcount="6">
    <b>                <Item id="5">
                        <caption>Freight * 2</caption>
                        <displayFolder>Sales Summary</displayFolder>
                        <expression Type="Float"><font color="#ff0000">=Fields!TwiceTheFreight.Value</font></expression>
    </b>            </fields>

    I've attached the schema file to this post. Simply change the connection string and load it into the viewer sample.

    Hope this helps and thanks again!

  • Replied 3 August 2017, 3:48 pm EST

    Thanks Luc.  I just posted a question on how to create a schema from a dataset.  After that, how do I programmatically modify the schema to add the calculated field?


  • Replied 3 August 2017, 3:48 pm EST

    To modify the schema to add the calculated field in code, you would need to use the schema builder.  Please keep in mind that you will not be able to open the schema file using the SchemaBuilder at this time.  Using the example Lucas provided, as well as the sample project I provided you in the Examples Thread, you would first add a QueryField to the SchemaBuilder with the calculation as the field's expression. For example something like the following
           sb.AddQueryFields({list of field names including "Freight"},
                 new QueryField("TwiceTheFreight").SetExpression<float>("=Fields!Freight.Value*2"), {any other calculated fields});

    Then when you go to add this calculated field to the schema as a measure field you could use something like the following:
            tmpMeasureField = new SchemaBuilder.MeasureField("TwiceTheFreight")

    Please feel free to let me know if you have any further questions.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels