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

Announcements
Posting on Qlik Community is temporarily paused. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
wunderch
Creator II
Creator II

value of max(date) in set analysis

Hi guys, 

I have the following challenge and I hope you can help me.

I have a table like that:

KFZDateKM
105.01.2025100

1

15.01.2025150
108.02.20251800
124.02.2025230
118.04.2025400
202.01.202570
210.01.202580
214.02.2025150

 

So I need a formula that gives me the "KM" of the min(date) and max(date) by KFZ

When I select Date from 01.01.2025 until 24.02.2025 I want 

KFZKM_MINKM_MAX
1100230
270150
   
   

 

Can anybody help me?

Labels (1)
1 Solution

Accepted Solutions
wunderch
Creator II
Creator II
Author

Sorry guys,
I found the solution myself.

 

Here is the magic formula:

KM_MIN:

=only(if(aggr(nodistinct min(Date), KFZ)=num(Date), KM))

KM_MAX:

=only(if(aggr(nodistinct max(Date), KFZ)=num(Date), KM))

 

View solution in original post

4 Replies
wunderch
Creator II
Creator II
Author

Sorry guys,
I found the solution myself.

 

Here is the magic formula:

KM_MIN:

=only(if(aggr(nodistinct min(Date), KFZ)=num(Date), KM))

KM_MAX:

=only(if(aggr(nodistinct max(Date), KFZ)=num(Date), KM))

 

marcus_sommer
MVP
MVP

I could imagine that you didn't need an aggr() within an if() and that only() might be risky in the case that there are more as a single record per date. Therefore you may try:

min({< Date = {"$(=date(min(Date))"}>} KM)
max({< Date = {"$(=date(max(Date))"}>} KM) 

wunderch
Creator II
Creator II
Author

I tried it, but sorry, it doesn't work.

dncontin
Contributor III
Contributor III

try

 

VehiclesData:
LOAD
KFZ,
Date(Date#(Date,'DD.MM.YYYY')) AS Date,
KM
INLINE [
KFZ, Date, KM
1, 05.01.2025, 100
1, 15.01.2025, 150
1, 08.02.2025, 1800
1, 24.02.2025, 230
1, 18.04.2025, 400
2, 02.01.2025, 70
2, 10.01.2025, 80
2, 14.02.2025, 150
];

dncontin_0-1761137800868.png

 

dncontin_1-1761137835341.png

min  = FirstSortedValue(KM, Date)
max = FirstSortedValue(KM, -Date)