Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello Qlik Community,
I've encountered a very peculiar behavior with an expression in Qlik Sense SaaS that seems to defy standard parsing rules and might indicate a bug. I'm hoping to get some insight, confirmation, or a potential explanation for this.
The Goal:
I'm trying to calculate the sum of Revenue for a specific Period defined by a variable vMaxPeriod, using the TOTAL qualifier to get a grand total (disregarding chart dimensions).
The Working Expression (Surprisingly):
My expression only works when structured exactly like this, including the // (comment) characters and specific line breaks:
Sum({$<Period={$(vMaxPeriod)}>} // TOTAL [GL_Hub] Revenue)
Key Observations for the Working Expression:
The Problem: Expressions That Don't Work (and why they should according to documentation):
If I remove the // comment, or if I consolidate TOTAL [GL_Hub] Revenue onto a single line after the set analysis, the expression breaks and returns an error.
Removing // (should work if // were just a comment):
Sum({$<Period={$(vMaxPeriod)}>} TOTAL [GL_Hub] Revenue)
Consolidating TOTAL and Field on one line (standard recommended syntax):
Sum({$<Period={$(vMaxPeriod)}>} TOTAL [GL_Hub] Revenue)
My Environment:
My Question to the Community:
I've verified that $(vMaxPeriod) resolves correctly to a valid period value and that [GL_Hub] Revenue is the correct field reference. The issue consistently lies with the presence/absence of // and the specific line breaks.
Any insights or similar experiences would be greatly appreciated!
Thank you,
Will
Hi, your 'GOOD' expression returns the same value with these expressions:
Sum({$<Period={$(vMaxPeriod)}>} //
TOTAL SomethingThatIsAnError
Revenue)
Sum({$<Period={$(vMaxPeriod)}>} TOTAL Revenue)
Also I don't understand your GOOD expression, it only shows the data for 202506 (1,165,164) in all the periods, It's really that what you want to show? What' are you trying to calcute by GL_Hub?
Hi, maybe it has something to do with he syntax after TOTAL, I'm not really sure what [GL_hub]. Is that a master item?
Usually after total there is only the field that has the measure, but in this case is GL_Hub and Revenue.
If Gl_Hub is a field to break the TOTAL, it should be between < and >, like: Sum({$<Period={$(vMaxPeriod)}>} TOTAL <GL_Hub> Revenue)
I don't have any clue about the //
Hi @William_Wistam ,
Did you try using the dimension '<' and '>' like follows and also using the TOTAL dimension before the Set Analysis ?
Sum( TOTAL <[GL_Hub]> {$<Period={$(vMaxPeriod)}>} Revenue)
Thanks
Vikram
Beside the already mentioned total-syntax it's not recommended to include any comments within the expressions because they are a potential source of error - especially if they are nested in any way.
Will
I don't want to exclude any parsing-bug but it seems quite unlikely to me because if nearly all common expressions wouldn't be working ...
... and if we look on the "not working" expression we see a result which seems to be quite correct. Therefore I assume that you are expecting a different result - probably by mistaken the functionality between an adjustment to the selection state per set analysis and adjusting the consideration of the object-dimensionalities by specifying a TOTAL statement.
A TOTAL ignores all relations to the dimensions of the current object - by extending it with something like <Field1, Field2> it ignores further all object-dimensions unless the extra listed ones. It's always performed against the available data-set which is specified by the set selections and/or the set adjustments within a set analysis - respectively the evaluation of the data-set comes always first.
In conclusion: the first expression is wrong and showed wrong results - IMO it should return always a syntax-error and not ignoring the set analysis by applying an empty comment. Maybe the direct line-break after the // "confused" the parser ... (you may play a bit with real comments like: // comment XYZ or /* abc */ to see if anything is changing - whereby like above mentioned it's not recommended to use comments within expressions - especially in regard to the efficiency of development-efforts and performance that if you would need ones that the data-model isn't suitable enough to support simple expressions).
Hi, your 'GOOD' expression returns the same value with these expressions:
Sum({$<Period={$(vMaxPeriod)}>} //
TOTAL SomethingThatIsAnError
Revenue)
Sum({$<Period={$(vMaxPeriod)}>} TOTAL Revenue)
Also I don't understand your GOOD expression, it only shows the data for 202506 (1,165,164) in all the periods, It's really that what you want to show? What' are you trying to calcute by GL_Hub?