My dataset consists of sentiment scoring and then sales amounts associated with the customers. However customer to sales records is a 1 to many collection so my sentiment scoring is repeated each time there is more than 1 sale.
I am attempting to use my sentiment id to identify the first instance of a sentiment to only count the score once. I have this calculation working, however, I cannot aggregate this in a table without including the ID in the table, which breaks the purpose for the visual.
firstValue(
ifelse(contains(Sentiment, 'Very Positive'),${ScoreVeryPositive},
ifelse(contains(Sentiment, 'Somewhat Positive'),${ScoreSomewhatPositive},
ifelse(contains(Sentiment, 'Neutral'),${ScoreNeutral},
ifelse(contains(Sentiment, 'Somewhat Negative'),${ScoreSomewhatNegative},
ifelse(contains(Sentiment, 'Very Negative'),${ScoreVeryPositive},NULL
))))),
[{sentiment_external_uid} DESC],
[{sentiment_external_uid}]
)
In the visual above I don’t want each ID listed, I want to be able to aggregate by other dimensions, like the name of the customer.
firstValue may not be the best approach so I am open to other methods!
Thank you!
Max
February 4, 2023, 12:44am
2
You will need to use SQL if you do not want to reference the id.
Can you try to use the rank function instead? For my use cases, I’ve found that it works better than first value or last value.
Take a look at this:
Hi,
I’m trying to figure out the use case for the firstValue or lastValue function. So far what I’m finding is that it’s easier to use the rank function to do the same thing. Is there a particular use case where the firstValue or lastValue function is better than the rank function?
Let’s say for example I want to find the last status for each id in the dataset below.
[lastValue versus rank]
If I use lastValue on the status field, I have to add all the fields to my visual in order to not get …
1 Like
Hi Max, do you mean I will need to group it in the SQL used to import the data to SPICE?
Max
February 6, 2023, 7:22pm
5
You will need to translate this
LexusHam:
firstValue(
ifelse(contains(Sentiment, 'Very Positive'),${ScoreVeryPositive},
ifelse(contains(Sentiment, 'Somewhat Positive'),${ScoreSomewhatPositive},
ifelse(contains(Sentiment, 'Neutral'),${ScoreNeutral},
ifelse(contains(Sentiment, 'Somewhat Negative'),${ScoreSomewhatNegative},
ifelse(contains(Sentiment, 'Very Negative'),${ScoreVeryPositive},NULL
))))),
[{sentiment_external_uid} DESC],
[{sentiment_external_uid}]
)
Into SQL. And use that new field in your table.
Then you will have this field and it won’t need to be referenced in the visual.