Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
appelture
Contributor
Contributor

Return distinct value where max date and How to convert date time string in Qlik Sense?

Hi, from the example data below I need to return the Model Name at the max Modified Date (which is a date time string - so this needs converting).

Model Name Modified Date (Date Time String)
Model A 2000-10-12 08:45:27
Model C 2008-10-30 16:16:19
Model A 2009-11-07 13:17:28
Model B 2012-06-05 10:17:11
Model A 2002-01-12 14:17:05
Model C 2003-02-20 14:23:00
Model C 2000-01-25 13:18:29

 

I am very new to Qlik but have seen the following formula that I think might work, however, I don't know how to also add in the conversion of the date time string: 

Sum(Aggr(
    If(Date = Max(TOTAL <ModelName> Date)), ModelName, Date))

Any help would be greatly appreciated. Thanks

Labels (3)
3 Solutions

Accepted Solutions
Andrei_Cusnir
Specialist
Specialist

Hello,

 

If my understanding is correct, then you want to display the value "Model B", because the biggest date from the dataset is "2012-06-05 10:17:11". Here are the steps that I have followed and some clarifications on your questions:

 

1. I have the following dataset:

IMAGE

 

2. Now I have created an Text & image object to display the value that you want

 

3. If you use as measure:  =Max([Modified Date (Date Time String)]) then the result is:

IMAGE

 

4. If you want this value to be formatted as date, then you can use the expression =Date(Max([Modified Date (Date Time String)]), 'DD/MM/YYYY hh:mm:ss') which will give you the output:

IMAGE

 

5. If you want to display the Model Name of the latest date though, you can use the expression: =FirstSortedValue([Model Name], -[Modified Date (Date Time String)]) which will give you the output:

IMAGE

 

 

I hope that this information was helpful. In case I have misunderstood the use case scenario, please elaborate in details by providing additional information. However, if it has helped you resolve the issue, please mark it as accepted solution to give further visibility to other community members. 
 

 

 

Help users find answers! Don't forget to mark a solution that worked for you! 🙂

View solution in original post

abhijitnalekar
Specialist II
Specialist II

Hi @appelture ,

you can follow the below steps to get the required output

1. COnver date time filed to Date

date(Modified_Date,'YYYY-MM-DD') as Modified_Date 

2. Use the below expression to get the Model names in front of max date

=if(Modified_Date = Max(TOTAL <ModelName> Modified_Date),ModelName)

 

abhijitnalekar_0-1644322399088.png

 

I hope i have understood the requirement correctly.

 

Regards,
Abhijit
keep Qliking...
Help users find answers! Don't forget to mark a solution that worked for you!

View solution in original post

salonicdk28
Creator II
Creator II

Hi,

is this you need as an output-

salonicdk28_0-1644322608293.png

Below steps to follow in script editor to achieve the above output

Temp:
Load * Inline [
ModelName,ModifiedDate
Model A,2000-10-12 08:45:27
Model C,2008-10-30 16:16:19
Model A,2009-11-07 13:17:28
Model B,2012-06-05 10:17:11
Model A,2002-01-12 14:17:05
Model C,2003-02-20 14:23:00
Model C,2000-01-25 13:18:29
];

Load ModelName,
Date(max(ModifiedDate)) as Date,
FirstSortedValue(ModelName,ModifiedDate)
Resident Temp
Group by ModelName;

Drop Table Temp;

View solution in original post

3 Replies
Andrei_Cusnir
Specialist
Specialist

Hello,

 

If my understanding is correct, then you want to display the value "Model B", because the biggest date from the dataset is "2012-06-05 10:17:11". Here are the steps that I have followed and some clarifications on your questions:

 

1. I have the following dataset:

IMAGE

 

2. Now I have created an Text & image object to display the value that you want

 

3. If you use as measure:  =Max([Modified Date (Date Time String)]) then the result is:

IMAGE

 

4. If you want this value to be formatted as date, then you can use the expression =Date(Max([Modified Date (Date Time String)]), 'DD/MM/YYYY hh:mm:ss') which will give you the output:

IMAGE

 

5. If you want to display the Model Name of the latest date though, you can use the expression: =FirstSortedValue([Model Name], -[Modified Date (Date Time String)]) which will give you the output:

IMAGE

 

 

I hope that this information was helpful. In case I have misunderstood the use case scenario, please elaborate in details by providing additional information. However, if it has helped you resolve the issue, please mark it as accepted solution to give further visibility to other community members. 
 

 

 

Help users find answers! Don't forget to mark a solution that worked for you! 🙂
abhijitnalekar
Specialist II
Specialist II

Hi @appelture ,

you can follow the below steps to get the required output

1. COnver date time filed to Date

date(Modified_Date,'YYYY-MM-DD') as Modified_Date 

2. Use the below expression to get the Model names in front of max date

=if(Modified_Date = Max(TOTAL <ModelName> Modified_Date),ModelName)

 

abhijitnalekar_0-1644322399088.png

 

I hope i have understood the requirement correctly.

 

Regards,
Abhijit
keep Qliking...
Help users find answers! Don't forget to mark a solution that worked for you!
salonicdk28
Creator II
Creator II

Hi,

is this you need as an output-

salonicdk28_0-1644322608293.png

Below steps to follow in script editor to achieve the above output

Temp:
Load * Inline [
ModelName,ModifiedDate
Model A,2000-10-12 08:45:27
Model C,2008-10-30 16:16:19
Model A,2009-11-07 13:17:28
Model B,2012-06-05 10:17:11
Model A,2002-01-12 14:17:05
Model C,2003-02-20 14:23:00
Model C,2000-01-25 13:18:29
];

Load ModelName,
Date(max(ModifiedDate)) as Date,
FirstSortedValue(ModelName,ModifiedDate)
Resident Temp
Group by ModelName;

Drop Table Temp;