Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

To fetch Previous month data

Hi,

I need to calculate the sum of values of previous month data depends on the current month selection,,,

PeriodName field consist of jan,2008,feb200

Sum ({$<PeriodName={$(#PeriodN)}>}Values)

i used this expression with the help option to get previous year values,,,PeriodN is the variable but it shows the current selected month and also nt showing values ,

i assigned PeriodN=PeriodName in input box proper,,,

i need sum values to be calculated for previous month....pls help me out,,thanks in advance

13 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP


Rod Jager wrote:=FIELDVALUE('PeriodName', FIELDINDEX('PeriodName', ONLY(PeriodName))-1)


Rod,

This technique requires that the periods were loaded in perfect ascending order, correct?

-Rob

Not applicable
Author

Hi Rob,

Yes, good point, the data needs to be in the correct order - isn't everyones 😉 ?

Rod

Not applicable
Author

Hi,

adding multiple expression its showing error in expression.Pls correct with the below condition.

if i select field values in PeriodName...it should display the sum of values related to that field.

if i select field values in SemName..it should display the sum of values related to that field.

Not applicable
Author

Hi btechrames,

If you want the calculation to be conditional then consider using the GetSelectedCount function or similar to evaluate if any elements have been selected from either the PeriodName or SemName fields and then apply logic accordingly.

As an (untested) example:

IF(GETSELECTEDCOUNT(PeriodName)=1 AND GETSELECTEDCOUNT(SemName)=0,
Sum ({$<PeriodName={'$(=FIELDVALUE('PeriodName', FIELDINDEX('PeriodName', ONLY(PeriodName))-1))'}>}Values),
IF(GETSELECTEDCOUNT(PeriodName)=0 AND GETSELECTEDCOUNT(SemName)=1,
Sum ({$<SemName={'$(=FIELDVALUE('SemName', FIELDINDEX('SemName', ONLY(SemName))-1))'}>}Values),
0
))

Not very elegant but I hope this helps.

Rod