Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
sweroy
Contributor
Contributor

Field selection

Hii,

 

Please can some one correct the below query.

 

I need to get the status depend on the date selected.

 

If the date selected is less than closed date then the status should be open.

Below Date2 is the Closed date and Date is the selected date in the report.

=if(Date2 = 'T' ,'Open'
,if( Date2 > GetFieldSelections(Date) ,'Open'
,if(STATUS_CD='Cancelled','Cancelled'
,if(STATUS_CD='Closed','Closed'))))

Labels (1)
5 Replies
hic
Former Employee
Former Employee

I assume that you want to calculate this in the UI. But then you have to consider that there are almost always several values possible within a single field. So your condition
      Date2 = 'T'
cannot be evaluated: The field reference "Date2" will return NULL if there is more than one possible value.

So either you need to use aggregation functions, e.g. Max(Date2) instead of Date2, or you need to use a dimension where there is only one Date2 and one STATUS_CD per dimensional value, e.g. by wrapping the whole expression in an Aggr().

See also https://community.qlik.com/t5/Design/Use-Aggregation-Functions/ba-p/1475833 

sweroy
Contributor
Contributor
Author

hi ,

 

Thank you for your reply,

 

But my requirement is i need to display the status by comparing two Date columns.

1) i have to select one date in UI and the table should display all the ID from the starting till the date selected.

2) if the ID is closed after the date which i have selected it should be shown as Open in the table.

Expected Result:

 

ID Date 2(Closed Date) Date(selected date in UI) Status  Original Status
1 1/5/2023 1/3/2023 Open Closed
2 1/4/2023 1/3/2023 Open closed
3 1/3/2023 1/3/2023 Open closed
4 1/2/2023 1/3/2023 Closed closed
5 1/1/2023 1/3/2023 Closed closed
6 12/31/2022 1/3/2023 Closed closed
hic
Former Employee
Former Employee

OK. Your dimension is "ID" and each ID has a "Date2" corresponding to closing date? And if it hasn't been closed, the "Date2" contains a 'T'?

But what about the field "Date"? How is that linked to these tickets?

You can probably create that table using the following:
Dimension: ID
Measure 1: Max(Date2) // Showing the (largest) closing date or blank (for 'T')
Measure 2: If(Only(Date2)='T' or Only(Date2) > Max(Date),'Open',STATUS_CD)

Max(Date) is returning the (largest/latest) selected date.

sweroy
Contributor
Contributor
Author

Can you please tell how can i use the below set analysis in Dimension

 

if(Date2  >  ( {<Year=,Month=,Date={"<=$(=max(Date))"}>}),'Open', 'Closed')

hic
Former Employee
Former Employee

You cannot mix If()-functions and set expressions the way you do. I suggest you read https://community.qlik.com/t5/Design/A-Primer-on-Set-Analysis/ba-p/1468344 to get a better understanding of how set analysis works.

I suspect that what you want to do, is to have a condition on the Date, and thereby assign 'Open' or 'Closed'. But to do this, you need to specify that you want to loop over the dates, and evaluate each date separately. This is done using
   =Aggr(..., Date)

Try the following as dimension:
   =Aggr(If(Only({<Date=>} Date) <= Date(Max(total Date)), 'Open', 'Closed'), Date)