I have a dataset that looks like this.
Date | Name | SurveyID | Score | Error |
---|---|---|---|---|
2022-02-17 | Jack | 10 | 95 | Name |
2022-02-17 | Jack | 10 | 95 | Address |
2022-02-16 | Tom | 9 | 100 | |
2022-02-16 | Carl | 8 | 93 | Zip |
2022-02-16 | Carl | 8 | 93 | |
2022-02-15 | Dan | 7 | 72 | Zip |
2022-02-15 | Dan | 7 | 72 | |
2022-02-15 | Dan | 7 | 72 | Name |
2022-02-15 | Dan | 6 | 90 | Phone |
2022-02-14 | Tom | 5 | 98 | Gender |
The formula for the calculate field I use before is: I name this calculated field as “Avg. Score”
avgOver({Score}, [Name], PRE_AGG)
This is giving incorrect average due to the duplicates on my dataset. I changed the calculate field to this:
SUM({Score}/ countOver({Score}, [{Survey ID}], PRE_AGG) )
/
DISTINCT_COUNT({Survey ID})
This new formula gave me the right average. However, I am unable to use this calculated field in my parameter as it gives me error that I cannot use a pre-filter/pre-agg values.
Now below are the formulas I have for my parameter calculated field. What I’m trying to achieve is a toggle that will allow end users to play with the data. It answers what if the X segment is able to hit a score of Y, what will my average look like, something like that. This is the photo for reference.
Formula for Simulated Avg. Score:
ifelse
(
{Segment} = 'A',
ifelse(${A}= 'Yes', ${NewScore}, {Avg. Score}),
{Segment} = 'B',
ifelse(${B}= 'Yes', ${NewScore}, {Avg. Score}),
{Segment} = 'C',
ifelse(${C}= 'Yes', ${NewScore}, {Avg. Score}),
{Segment} = 'D',
ifelse(${D}= 'Yes', ${NewScore}, {Avg. Score}),
{Segment} = 'E',
ifelse(${E}= 'Yes', ${NewScore}, {Avg. Score}),
{Avg. Score}
)
{NewScore} Parameter is just a control that is an integer type with a static value of 98. This is the “Change Score To” on the screenshot.
I have created string parameters from Segment A to E for the “Yes or No” toggle. {A} to {E}
This is the calculated field I have for the {Segment} parameter.
ifelse
(
{Avg. Score}>= 98,'A',
{Avg. Score}>= 95,'B',
{Avg. Score}>= 90,'C',
{Avg. Score}>= 80,'D',
'E'
)
The initial formula I have for ‘Avg. Score’ seem to work fine with the simulated avg. score calculated field.
avgOver({Score}, [Name], PRE_AGG)
Now that I changed this to this formula below, I am unable to use this field due aggregated values. How do I solve this? Please help. Thank you.
SUM({Score}/ countOver({Score}, [{Survey ID}], PRE_AGG) )
/
DISTINCT_COUNT({Survey ID})