# CD Reference Number

## Question

I have a numeric reference id from 1 to n, which I use in a view scheme to list CDs by this reference id, grouped in groups of 160 discs. Unfortunately, the group by box is 0-based, so CDs are listed as reference ids:

```  0 - 159
160 - 319
...
```

I'd like

```  1 - 160
161 - 320
```

Is there a way to do this?

One approach is to use an expression that maps the possible range of reference ids into a set of categories. Here is one such expression that creates groups of size 160 (whitespace added for clarity)

```  If(IsEmpty([Ref ID],1),
Unassigned,
```

The expression outputs "Unassigned" if the reference id is empty. This protects against empty reference id values in the latter portions of the expression.

The bulk of the expression maps, for example, reference id values 1 to 160 into just two numbers, 1 and 160. This allows creating the categories that will be used in selections. Ignoring the PadNumber() portion, which just adds leading 0's for alignment, the first part

```  Math(160*(FormatNumber(Math(([Ref ID]-1)/160+0.5))-1)+1)
```

creates the first portion of the category label (eg. the "1" in "1 - 160"). It does this by first subtracting 1 from the reference id (thus making it 0-based), and dividing the result by the group size (here, 160), which provides a value from 0 to less than 1. By adding 0.5, FormatNumber helps truncate, leaving only the whole integer. Finally, multiplying by the group size of 160 creates the various steps (eg. 1 - 160, 161 - 320, etc.). The next portion of the expression

```  Math(160*(FormatNumber(Math(([Ref ID]-1)/160+0.5))-1)+160)
```

does the same thing essentially, but outputs the end of the range (eg. the "160" in "1 - 160"). The two expressions are concatenated but the " - " to create the category label.

To change the grouping, replace all "160" values to the desired grouping size. Here is an example using a Search list, with several reference id categories in the pane, with group sizes of 160, 10, and 1.

First thing that springs to mind is to use the new search list option. The only drawback with that approach is that it's not maintenance free like the 'group items' option is.

You would name the search list "Reference ID" and then add searches like so:

1 - 160 [=isrange([reference id],1-160)]=1
161 - 320 [=isrange([reference id],161-320)]=1
321 - 480 [=isrange([reference id],321-480)]=1
481 - 640 [=isrange([reference id],481-640)]=1

and so on. It will work for you, but you'll need to add searches as the ref id list grows outside the highest grouping.

... and that is how you use expressions in searches! [=<EXPRESSION>]=1 (use one for positive results, or zero for negative results)

## Result

Marko - fantastic thanks! This worked like a charm.

Adding a new expression every 160 CDs is trivial, so maintainence is not a problem for me.

I suppose it would be a nice feature if the Group By could have a check box which would make numeric groupings 1-based instead of 0-based, or even more general yet, and offset that could be added to numeric Group By's.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8134772,"math_prob":0.86754835,"size":3200,"snap":"2020-45-2020-50","text_gpt3_token_len":836,"char_repetition_ratio":0.1301627,"word_repetition_ratio":0.0,"special_character_ratio":0.30625,"punctuation_ratio":0.11890244,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97749513,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-12-01T12:09:43Z\",\"WARC-Record-ID\":\"<urn:uuid:1128bb44-506d-4e3d-a8e7-de6d0c1b53ee>\",\"Content-Length\":\"17143\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:4437c164-f204-4ffc-baaf-8593d40671a9>\",\"WARC-Concurrent-To\":\"<urn:uuid:092d5ff0-d77c-4c43-a38f-e4c9aa813ee8>\",\"WARC-IP-Address\":\"216.14.187.173\",\"WARC-Target-URI\":\"https://wiki.jriver.com/index.php?title=CD_Reference_Number&direction=prev&oldid=6783\",\"WARC-Payload-Digest\":\"sha1:FPYN4P5C5HG5HBY3X2VIKOY3CJAGT544\",\"WARC-Block-Digest\":\"sha1:6JPKEORIS7NJDFPVKFGBFDHMAMMCP2DR\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-50/CC-MAIN-2020-50_segments_1606141674082.61_warc_CC-MAIN-20201201104718-20201201134718-00429.warc.gz\"}"}