I have gone through
https://community.looker.com/technical-tips-tricks-1021/how-to-make-a-weighted-average-30239but am facing an error.
I have a dimension for weight, a dimension for case types and a dimension for case IDs. I want to get the weighted average for cases based on their case types. the formula i need to use is:
weighted average = ( case_count(for case_type A)* weight% + case count(for case_type B)* weight% + case count(for case_type C)* weight% ) / (total case_count)
dimension: weight { # differs depending on case type associated with case
type: number
sql: ${TABLE}.weight ;;
}
dimension: case_type { # each case type has different weight
type: string
sql: ${TABLE}.case_type ;;
}
dimension: case_count {
type: count_distinct
sql: ${TABLE}.case_id ;;
}
dimension: weighted_count {
type: number
sql: ${case_count} * ${weight} ;;
}
measure: weighted_average {
type: number
sql: sum(${weighted_count})/${request_count} ;;
}
this gives the error “Aggregate functions cannot be nested” due to sum function in the weighted_average measure. is there a way to fix this?