Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

etrotter
Contributor II

GetCurrentSelections

Hi,

Trying to write an if statement with GetCurrentSelections:

If(GetFieldSelections(Week)= Date(Weekend(Today()),'MM/DD/YYYY'),1,0)

my date format is 01/26/2018

Please let me know if you have any ideas on how to get it working.

Thanks!

1 Solution

Accepted Solutions
MVP
MVP

Re: GetCurrentSelections

Adding a Date() formatting function to the left side will not work, since the value you want to format is a text value.

Try interpretation function Date#()

9 Replies
thiago_justen
Valued Contributor III

Re: GetCurrentSelections

Erica,

What is your output? The expression looks like OK (considering that field Week is formated as you said).

Cheers

Thiago Justen Teixeira Gonçalves
WhatsApp: 24 98152-1675
Skype: justen.thiago

Re: GetCurrentSelections

I'm guessing there is a timestamp attached to your field, but you're only concerned about the date.  You can use floor() to ignore the timestamp.  This formula should work:

If(Floor(GetFieldSelections(Week)) = Floor(Weekend(Today())),1,0)

etrotter
Contributor II

Re: GetCurrentSelections

Outputs:

GetCurrentSelections(Week): Week:01/27/2018

Date(Weekend(Today()),'MM/DD/YYYY'): 01/27/2018

I have also tried 'Week:'&Date(Weekend(Today()),'MM/DD/YYYY'): Week:01/27/2018

as

If(GetFieldSelections(Week)= 'Week:'&Date(Weekend(Today()),'MM/DD/YYYY'),1,0) and that still didn't work

OmarBenSalem
Esteemed Contributor

Re: GetCurrentSelections

Your construction of the weeend date seems to be correct;

but GetFieldSelections(Week) do not return the Week date but sthing like

Week: 01/26/2018

so ur condition has to be sthing like :

if(trim(SubField( GetCurrentSelections(Week),':',2))= Date(Weekend(Today()),'MM/DD/YYYY'),1,0)


per anaogy result if condition is:

if(trim(SubField( GetCurrentSelections(Year),':',2))=max({1}Year),1,0)

Capture.PNG

else

Capture.PNG

thiago_justen
Valued Contributor III

Re: GetCurrentSelections

It seems you have a date field formated as a timestamp, as Nicole said. Try Nicole's expression and then tell us what happens.

Cheers

Thiago Justen Teixeira Gonçalves
WhatsApp: 24 98152-1675
Skype: justen.thiago
etrotter
Contributor II

Re: GetCurrentSelections

I have the week selected and I used:

if(trim(SubField( GetCurrentSelections(Week),':',2))= Date(Weekend(Today()),'MM/DD/YYYY'),1,0)

and its still giving me a zero, I also tried:

if(Date(trim(SubField( GetCurrentSelections(Week),':',2)))=Date(Weekend(Today()),'MM/DD/YYYY'),1,0)

and its still a zero.


Its strange, I both fields into a text object to see their outputs and they are exactly the same, I'm not sure why it refuses to match.

Capture.PNG

MVP
MVP

Re: GetCurrentSelections

The right value shows a leading zero, and you are comparing the text values char by char.

MVP
MVP

Re: GetCurrentSelections

Adding a Date() formatting function to the left side will not work, since the value you want to format is a text value.

Try interpretation function Date#()

OmarBenSalem
Esteemed Contributor

Re: GetCurrentSelections

what if u try as :

if(trim(SubField( GetCurrentSelections(Week),':',2))= Date(Weekend(Today()),'M/DD/YYYY'),1,0)


OR


if(trim(SubField( GetCurrentSelections(Week),':',2))= Date#(Weekend(Today()),'M/DD/YYYY'),1,0)



Community Browser