I see here 2 ways of solving this. If you really want to rely on one variable, then you have to execute two queries combined with an append. Always one of the queries will use a filter condition which is false for every record.
//desc sorting
fetch logs, from: $dt_timeframe_from, to:$dt_timeframe_to
| filter timestamp >= if($aggregation == "max", astimestamp($dt_timeframe_from), else: now()+1d)
| sort timestamp desc
//asc sorting
| append [
fetch logs, from: $dt_timeframe_from, to:$dt_timeframe_to
| filter timestamp >= if($aggregation == "min", astimestamp($dt_timeframe_from), else: now()+1d)
| sort timestamp asc
]
Or you introduce a new Variable called direction with values “descending” and “ascending”. Then you could use it like following:
fetch logs
| sort timestamp, direction: $direction
Best,
Sini