Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

Not applicable

Variables/SA

Hi,

I'm trying to get a count for the current and previous month using set analysis with a variable:

To get the current month-year:

date(today(),'MMM-YY')

Set analysis formula:

count({$<MonthYear = {$(vcurrmonth)}>}dc_code)

As far as I am aware the MonthYear and current month variable are in the same format.

Can anyone tell me what I am doing wrong?

Thanks.

10 Replies
MVP
MVP

Re: Variables/SA

Try enclosing your variable in single quotes:

count({$<MonthYear = {'$(vcurrmonth)'}>}dc_code)

Not applicable

Re: Variables/SA

Thanks for the response.

No luck I'm afraid...although I now get a 0 instead of a null...

Re: Variables/SA

HI

Did u check the format? Its MMM-YY  or MMM-YYYY?

MonthYear format?

After that

count({$<MonthYear = {'$(vcurrmonth)'}>}dc_code)

Hope it helps

Not applicable

Re: Variables/SA

Hi

Yes I'm sure the format is the same as when I use an IF statement to put a flag on records for the current and previous months that works ok.

Thanks for the reply

MVP
MVP

Re: Variables/SA

Are you trying to use the set expression in a chart with a date dimension (e.g. YearMonth)? For a comparison of counts for different time periods?

Then try

count(TOTAL {$<MonthYear = {'$(vcurrmonth)'}>}dc_code)

Not applicable

Re: Variables/SA

Currently I'm not using a dimension - however I tried your suggestion but it still doesn't work.

The variable is an expression, will that make a difference?

Re: Variables/SA

The format is in principle irrelevant. The comparison is made on the number behind. (It's a dual so the field has both a numeric and a string representation.)

I would define the variable as

Let vCurrMonth = Num(MonthStart(today()));

and use this integer in a comparison with MonthYear (that also should be created using MonthStart).

HIC

kumarnatarajan
Valued Contributor

Re: Variables/SA

Check both field format then Try the below syntex

=count({$<MonthYear = {$(=vcurrmonth)}>}dc_code)

Not applicable

Re: Variables/SA

Thanks Henric

The set analysis doesn't seem to accept using num inside the expression (for the monthyear), is this something that needs to be done in the script?

Community Browser