Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
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
swuehl
MVP
MVP

Try enclosing your variable in single quotes:

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

Not applicable
Author

Thanks for the response.

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

MayilVahanan

HI

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

MonthYear format?

After that

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

Hope it helps

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
Not applicable
Author

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

swuehl
MVP
MVP

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
Author

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?

hic
Former Employee
Former Employee

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
Partner - Specialist
Partner - Specialist

Check both field format then Try the below syntex

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

Not applicable
Author

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?