# Get minimum/maximum value from loop in template script?

**URL:** https://community.mp3tag.de/t/get-minimum-maximum-value-from-loop-in-template-script/62114
**Category:** Support
**Created:** [September 13, 2023, 7:26pm UTC](https://community.mp3tag.de/t/get-minimum-maximum-value-from-loop-in-template-script/62114 "2023-09-13T19:26:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Black\_Platypus](https://community.mp3tag.de/user_avatar/community.mp3tag.de/black_platypus/32/14795_2.png) [@Black\_Platypus](https://community.mp3tag.de/u/Black_Platypus)
#### Post date: [September 13, 2023, 7:26pm UTC](https://community.mp3tag.de/t/get-minimum-maximum-value-from-loop-in-template-script/62114/1 "2023-09-13T19:26:16Z")

</div>

Is there a way I can get minimum/maximum values from numeric fields, such as `%_bitrate%`, from a list of files (`$loop`)?

Specifically, I'm looking to create an output like

> Bitrate: 800-1500 kbps

For a list of files with values like

> Track 1: Bitrate: 900 kbps  
> Track 2: Bitrate: 800 kbps  
> Track 3: Bitrate: 1200 kbps  
> Track 4: Bitrate: 1500 kbps  
> Track 5: Bitrate: 1000 kbps

Is there a way to do this?

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [September 13, 2023, 7:29pm UTC](https://community.mp3tag.de/t/get-minimum-maximum-value-from-loop-in-template-script/62114/2 "2023-09-13T19:29:45Z")

</div>

The search words "minimum maximum export" get this hit:

> [@Changing Tag - Filename to Range of Options?](https://community.mp3tag.de/t/changing-tag-filename-to-range-of-options/18130):
>
> Hello, apologies if this is posted somewhere, I was unable to find it. When cataloguing my audiobooks, I have Tag-Filename set up as: Artist - Series # - Title (Genre) (Bit Rate) (Format) But some (many) have varying bit-rates between files. So for example: J.K. Rowling - Harry Potter 01 - Harry Potter and the Philosopher's Stone (Fantasy) (48k) (MP3) J.K. Rowling - Harry Potter 01 - Harry Potter and the Philosopher's Stone (Fantasy) (64k) (MP3) J.K. Rowling - Harry Potter 01 - Harry Pot…

---

<div class="post-metadata">

### Author: ![Black\_Platypus](https://community.mp3tag.de/user_avatar/community.mp3tag.de/black_platypus/32/14795_2.png) [@Black\_Platypus](https://community.mp3tag.de/u/Black_Platypus)
#### Post date: [September 13, 2023, 7:55pm UTC](https://community.mp3tag.de/t/get-minimum-maximum-value-from-loop-in-template-script/62114/3 "2023-09-13T19:55:31Z")

</div>

So sorry, I missed that!  
Thank you 👍 😊

---

<div class="post-metadata">

### Author: ![Black\_Platypus](https://community.mp3tag.de/user_avatar/community.mp3tag.de/black_platypus/32/14795_2.png) [@Black\_Platypus](https://community.mp3tag.de/u/Black_Platypus)
#### Post date: [September 13, 2023, 8:03pm UTC](https://community.mp3tag.de/t/get-minimum-maximum-value-from-loop-in-template-script/62114/4 "2023-09-13T20:03:34Z")

</div>

FWIW, here is the line that compares, sets and outputs the min/max for the `%_bitrate%` field, using variables called `brMin` and `brMax` for intermediate values.  
Replace those with what you're after if you're looking to do something similar

```auto
$loop(%File%)$loop(%File%)$puts(brMin,$if($or($less(%_bitrate%,$get(brMin)),$less($get(brMin),1)),%_bitrate%,$get(brMin)))$puts(brMax,$if($or($grtr(%_bitrate%,$get(brMax)),$less($get(brMax),1)),%_bitrate%,$get(brMax)))$loopend()$get(brMin)-$get(brMax)$loopend() kbps

```

This will render

> 800-1500 kbps

for the above example scenario.

Thank you to @rko31415, that looks like a nightmare to set up 😅

---

<div class="post-metadata">

### Author: ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)
#### Post date: [October 13, 2023, 8:04pm UTC](https://community.mp3tag.de/t/get-minimum-maximum-value-from-loop-in-template-script/62114/5 "2023-10-13T20:04:21Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
