'Expression to dynamically determine average of a set of metrics based on specified date range parameter in SSRS

I am trying to replicate a report in a Visual Studio in Power BI report builder, however I have a column where I am trying to use an expression to dynamically calculate an average of set metrics using from- and to- date parameters i.e whenever I choose a range of date parameters, it dynamically gets the average of that metric depending on the number of months specified, expression also has a logical expression where "if value of parameter A is indicated, it does the metrics calculation based on that value, otherwise it calculates the expression based on the other parameter value. Each time I run the expression, I get error code:

There is an error on line 0 of custom code: [BC30035] Syntax error.

Below is the expression;

  =IIF(Parameters!UnitofMeasure.Value= "A", 
     Code.DivideBy(
                   Code.SumLookup(
                                  LookupSet(Fields!SubvalueA.Value, Fields!SubvalueA.Value, Fields!MVA.Value, "DatasetA")
                                  )
                   ,CSTR(DATEDIFF(Dateinterval.Day, CDATE(TRIM(Parameters!FromDateRange.Label)), CDATE(TRIM(Parameters!ToDateRange.Label)))) + Code.DaysInMonth(CDATE(TRIM(Parameters!ToDateRange.Label)))
                    )
     ,Code.DivideBy(
                     Code.SumLookup(
                                    LookupSet(Fields!SubvalueA.Value, Fields!SubvalueA.Value, Fields!IVA.Value, "DataSetA")
                                   )
                   , CSTR(DATEDIFF(Dateinterval.Day, CDATE(TRIM(Parameters!FromDateRange.Label)), CDATE(TRIM(Parameters!ToDateRange.Label)))) + Code.DaysInMonth(CDATE(TRIM(Parameters!ToDateRange.Label)))
                   )
     )

I need someone to help me look into this. Also, I have tried to use the 'values' instead of 'label' for the date range parameter but no difference. The date range in the values and labels are in varchar data types, the values in the date range is in the format of '201901' while label i.e what users see '2019 - Jan'. Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source