# New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

New Contributor II

## 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!

10 Replies
Honored Contributor II

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

where are you using that variable ?

New Contributor II

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

Into chart: table

Honored Contributor II

## 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.

Honored Contributor II

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

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

New Contributor II

## 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.

Honored Contributor II

## 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?

New Contributor II

## 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;

Honored Contributor II

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

what you get with the below expression ?

=num(weekday(today()))

New Contributor II

## 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