Dynamic measures can calculate different metrics depending on the report's user-defined parameters. With dynamic measures you can avoid same report duplication when the only difference is a metric (or its calculation). A primary use cases for dynamic measures are:
How dynamic measures works in a report:
Expression:
Sql.Raw(
new dictionary{
{"Sales Amount", "unit_price*quantity"},
{"Items Delivered", "quantity"}
}[ IfNull(Parameter["param_dynamic_metric"], "Sales Amount")] )
Sql.Raw function is used to insert the value into SQL query 'as-is' (not as a constant).new dictionary{} defines SQL expressions for allowed "param_dynamic_metric" choices and also guarantees that user-entered
value is not inserted into SQL directly (to prevent a possibility of SQL-injections).
@param_dynamic_metric which means it is resolved with parameter's value.
Type = Sum if all dynamic metrics have the same aggregate function but different columns. This can be FirstValue otherwise.
Parameters = @param_dynamic_metric_sql which resolves a column name (or custom SQL expression) dynamically.