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?



    Thanks
  • Replied 3 August 2017, 3:48 pm EST

    Dan,

    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:

       
           
           
           
    ...
    ...
           
                =Day(Fields!OrderDate.Value)
           

            TwiceTheFreight">
                =Fields!Freight.Value*2
           


       

       

           
                Measures
                Measures
                Measures
               
    ...
    ...
                   
                        TwiceTheFreight
                        Measure
                        Freight * 2
                        Sales Summary
                        =Fields!TwiceTheFreight.Value
                        Sum
                        c
                   

               

    ...
    ...
           

       




    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!
    Luc

    2007/10/NwindMDB-SalesProductsSuppliers.zip
  • 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?


    Thanks

  • Replied 3 August 2017, 3:48 pm EST

    Dan,
    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("=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")
              .SetKeyExpression("=Fields!TwiceTheFreight.Value");
           tmpMeasureDimension.AddField(tmpMeasureField);

    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