There are differences in the way you create the variable, with or without an equal sign.
It also important, in which context you want to use the variable. Are you using it within an aggregation function like sum? If your variable expands to text, this will not work, since an aggregation function like your sum() is not allowed within another aggregation function without using advanced aggregation (i.e. the aggr() function).