Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

If condition with only()

hey all,

I am facing a problem with Rolling 12 months bar chart. I want the chart to show the avg for each month(for 12 month from the month selected). And default to the latest month for which the data is available(If no month/year is selected). The following is my expression :

If(GetSelectedCount([Month ])=0 and GetSelectedCount([Year ])=0,

Only({$<MonthYearID={"<= $(=$(vMax)) >= $(=$(vMax)-11)"},Location = {$(=SubField(GetfieldSelections(Location),':',-1))} >}R_AvgCardSwipes),

Only({$<MonthYearID={"<= $(=max(MonthYearID)) >= $(=max(MonthYearID)-11)"},Location = {$(=SubField(GetfieldSelections(Location),':',-1))} >}R_AvgCardSwipes))

The Only() expressions works fine when alone but not when used with the if condition.

Thanks .

11 Replies
sunny_talwar

Both Only expressions work stand alone? and both don't work when you make and clear selection???

Anonymous
Not applicable
Author

Yes Sunny. Both expressions work when alone.

sasiparupudi1
Master III
Master III

try

Only({$<Month =,Year=,MonthYearID={"<= $(=$(vMax)) >= $(=$(vMax)-11)"},Location = {$(=SubField(GetfieldSelections(Location),':',-1))} >}R_AvgCardSwipes),

Anonymous
Not applicable
Author

Thanks. But there is no change.

sunny_talwar

Is the problem that it isn't giving you the result you expect or its just not giving any result???

Anonymous
Not applicable
Author

From what I can interpret, Values get passed to variables in both the expressions. Both expressions are selected.

sunny_talwar

Well even if the value goes to both the expression, only one of the if statement clauses are going to be true. So either 1st expression or the 2nd expression is going to be evaluated.

What happens when you replace Only() with Avg(), May be there are more than one value to be displayed and Only just isn't possible.

Anonymous
Not applicable
Author

Thanks Sunny. But the values are wrong .

I have found a work around. Instead of the if condition, I am using two charts with conditional hiding - One when no selection and other when there is a selection.

Thanks all.

sunny_talwar

May I suggest two expressions, instead of two charts? and conditionally hiding/showing them based on your condition. Just one less chart to worry about

HTH

Best,

Sunny