# Cascading if statement

**URL:** <https://community.mp3tag.de/t/cascading-if-statement/42465>\
**Category:** Support\
**Created:** [July 26, 2018, 12:29pm UTC](https://community.mp3tag.de/t/cascading-if-statement/42465 "2018-07-26T12:29:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![djdizzle](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/ed8c4c/32.png) [@djdizzle](https://community.mp3tag.de/u/djdizzle)\
**Post date:** [July 26, 2018, 12:29pm UTC](https://community.mp3tag.de/t/cascading-if-statement/42465/1 "2018-07-26T12:29:30Z")

</div>

Hi,

I am trying to use the following if statements to format the Album tag based on if either the temporary ReleaseEdition and ReleaseType tags or both are filled. However I can not get the statement covering both tags to process.

```
[#0]
T=5
F=ALBUM
1=$if(%releaseedition%,%album% '{'%releaseedition%'}',if(%releasetype%,%album% '{'%releasetype'}',if(%releaseedition% %releasetype%,%album% '{'%releaseedition% %releasetype%'}',%album%)))
```

---

<div class="post-metadata">

**Author:** ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)\
**Post date:** [July 26, 2018, 1:00pm UTC](https://community.mp3tag.de/t/cascading-if-statement/42465/2 "2018-07-26T13:00:21Z")

</div>

If you don't want to find all your syntax errors for the formula  
`$if(x,y,z) = if x is true, y is returned, otherwise z.`  
you can try to make 3 much easier, single actions.

But first you have to explain what do you want to do exactly?  
If your temporary tag `%releaseedition%` is filled, then you want to fill the official tag `%album%` with the content of `{%releaseedition%}` (inlcuding curly brackets)?

---

<div class="post-metadata">

**Author:** ![djdizzle](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/ed8c4c/32.png) [@djdizzle](https://community.mp3tag.de/u/djdizzle)\
**Post date:** [July 26, 2018, 1:18pm UTC](https://community.mp3tag.de/t/cascading-if-statement/42465/3 "2018-07-26T13:18:28Z")

</div>

The first two if statements work correctly, it's the third that is this issue.  
`if(%releaseedition% %releasetype%,%album% '{'%releaseedition% %releasetype%'}',%album%)`

I am trying to test if both `%releaseedition%` and `%releasetype%` tags exist then append them to the Album tag in curly braces.

Desired outcomes:

`AlbumTitle {Deluxe}`, `AlbumTitle {Single}` or `AlbumTitle {Deluxe Single}`.

---

<div class="post-metadata">

**Author:** ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)\
**Post date:** [July 26, 2018, 1:25pm UTC](https://community.mp3tag.de/t/cascading-if-statement/42465/4 "2018-07-26T13:25:13Z")

</div>

Something like  
if(**$and(**%releaseedition% **,** %releasetype%**)**,%album% '{'%releaseedition% %releasetype%'}',%album%)

[Boolean functions:](https://docs.mp3tag.de/scripting)  
`$and(x,y) -> returns true if x and y are true`

---

<div class="post-metadata">

**Author:** ![djdizzle](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/ed8c4c/32.png) [@djdizzle](https://community.mp3tag.de/u/djdizzle)\
**Post date:** [July 26, 2018, 2:05pm UTC](https://community.mp3tag.de/t/cascading-if-statement/42465/5 "2018-07-26T14:05:12Z")

</div>

> [@LyricsLover](#):
>
> if( **$and(** %releaseedition% **,** %releasetype% **)** ,%album% '{'%releaseedition% %releasetype%'}',%album%)

`if(,Heroes (We Could Be) {Deluxe Single},Heroes (We Could Be))`

---

<div class="post-metadata">

**Author:** ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)\
**Post date:** [July 26, 2018, 2:22pm UTC](https://community.mp3tag.de/t/cascading-if-statement/42465/6 "2018-07-26T14:22:55Z")

</div>

Copy & paste your line 1= into an editor like notepad++ and break the lines like

```
$if(%releaseedition%,%album% '{'%releaseedition%'}',
 if(%releasetype%, %album% '{'%releasetype'}',
 if($and(%releaseedition% , %releasetype%) ,%album% '{'%releaseedition% %releasetype%'}',%album%)))

```

Then re-read my first answer with the `$if(x,y,z)`-command

You can read your 3 lines above like:  
IF %releaseedition% is true (= in this case _not empty_), then fill %album% with the content of {%releaseedition%}  
IF %releaseedition% is false (= in this case _empty_), then check this:  
IF %releasetype% is true (= in this case _not empty_), then fill %album% with the content of {%releasetype%}

if you complete the `$if(x,y,z)` logic for OTHERWISE Z  
In which case will your 3rd IF-condition ever be reached and executed?

---

<div class="post-metadata">

**Author:** ![djdizzle](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/ed8c4c/32.png) [@djdizzle](https://community.mp3tag.de/u/djdizzle)\
**Post date:** [July 26, 2018, 2:30pm UTC](https://community.mp3tag.de/t/cascading-if-statement/42465/7 "2018-07-26T14:30:48Z")

</div>

I've decided to separate each statement into individual actions. The previous reply is the result of the if $and statement only.

---

<div class="post-metadata">

**Author:** ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)\
**Post date:** [July 26, 2018, 2:42pm UTC](https://community.mp3tag.de/t/cascading-if-statement/42465/8 "2018-07-26T14:42:13Z")

</div>

Did you forget the leading dollar sign **$** in front of the IF-condition if you use it as individual action?

`$if($and(%releaseedition% , %releasetype%) ,%album% '{'%releaseedition% %releasetype%'}',%album%)`  
which reads:  
IF both %releaseedition% AND %releasetype% are true (= in this case _not empty_), then fill %album% with the content of {%releaseedition% SPACE %releasetype%}  
IF one of %releaseedition% OR %releasetype% are false (= in this case _empty_), then let %album% remain unchanged

---

<div class="post-metadata">

**Author:** ![djdizzle](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/ed8c4c/32.png) [@djdizzle](https://community.mp3tag.de/u/djdizzle)\
**Post date:** [July 26, 2018, 3:00pm UTC](https://community.mp3tag.de/t/cascading-if-statement/42465/9 "2018-07-26T15:00:33Z")

</div>

Oops, my bad. Thanks 🙂

---

<div class="post-metadata">

**Author:** ![ryerman](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ryerman/32/5285_2.png) [@ryerman](https://community.mp3tag.de/u/ryerman)\
**Post date:** [July 26, 2018, 4:32pm UTC](https://community.mp3tag.de/t/cascading-if-statement/42465/10 "2018-07-26T16:32:02Z")

</div>

> [@djdizzle](#):
>
> I am trying to use the following if statements to format the Album tag based on if either the temporary ReleaseEdition and ReleaseType tags or both are filled

Another way is to use the power of square brackets in the format string, like this:  
`$Replace(%album% [{%releaseedition% %releasetype%}],{ ,{, },})`

See here: [Characters with special functionality](https://docs.mp3tag.de/scripting)

---

<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:** [July 31, 2019, 4:37am UTC](https://community.mp3tag.de/t/cascading-if-statement/42465/12 "2019-07-31T04:37:19Z")

</div>

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