10 Replies Latest reply: Oct 25, 2017 11:33 AM by Shahbaz Khan Mohammed

# Is possible to use if statement into variable calculation?

Hi,

I am trying to use if condition into variable calculation. I need to identify if day of the week is Monday to go back 2 days until Saturday.

the expresions works well, I valideted both,  however the if condition is not working well.

if( num(weekday(Date)) = 1,

Count(

{\$

+

}

distinct Numero_OrdenVenta),

Count(

{\$

+

}

distinct Numero_OrdenVenta))

Somebody can help me?

thank you!

• ###### Re: Is possible to use if statement into variable calculation?

where are you using that variable ?

• ###### Re: Is possible to use if statement into variable calculation?

Into chart: table

• ###### Re: Is possible to use if statement into variable calculation?

to go further you should provide a sample document with your issue.

• ###### Re: Is possible to use if statement into variable calculation?

I guess it should work. You are just storing the expression as is into variable.

If you expression is working without adding it to variable then break it down and use 2 variable instead.

Maybe use

Variable1:

Count(

{\$

+

}

distinct Numero_OrdenVenta)

Variable2:

Count(

{\$

+

}

distinct Numero_OrdenVenta))

This into Variable and if( num(weekday(Date)) = 1, separate?

Ex:

if( num(weekday(Date)) = 1, \$(Variable1),\$(Variable2))

Not sure if it will work... but I usually break down large expressions into different sets of variable.

• ###### Re: Is possible to use if statement into variable calculation?

I created the both variables, I can see the both variables return the result well. However the if sentence does not works well, looks like the condition is not valide becase does not return the first variable, just the second one.

• ###### Re: Is possible to use if statement into variable calculation?

it could be caused by your table dimensions.

which dimensions and measures are you using in table object?

• ###### Re: Is possible to use if statement into variable calculation?

Before insert into table I am using KPI to see the number, I think my problem is the if condition, I should SET in Main something.... like SET FirstWeekDay=6;

• ###### Re: Is possible to use if statement into variable calculation?

what you get with the below expression ?

=num(weekday(today()))

• ###### Re: Is possible to use if statement into variable calculation?

Well I need to use Date, because the measurement is any date. Any way I set "SETFirstWeekDay=0" ; and now IF statement Works.

Thank you for your help, I really appreciated

• ###### Re: Is possible to use if statement into variable calculation?

Your Count expression would only satisfy if >>>>>> if( num(weekday(Date)) = 1,

Which means the condition has to be selected manually.

Maybe use

If(Getselectedcount(Weekday)=0, and then your condition ?

You can create Weekday field in backend

Weekday(Date) as Weekday