INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: [Expression] Merging field values into one field [solved]  (Read 1565 times)

StFeder

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1493
  • Fight! You may win. If you don't, you already lost
[Expression] Merging field values into one field [solved]
« on: April 22, 2015, 06:15:59 am »

I have a user field Dance which contains the ballroom dance. Now I want to create an expression field which NOT contains the full name of a dance (eg. "Slow Waltz" or "Tango") but its abbreviations (eg. "SW" or "TG"). Some songs are tagged for two dances, so the expression I need should "look" if the Dance field contains "Slow Waltz" and if yes put "SW" inside the new abbreviation field.

Of course I could use an ifelse function, but I have many song tagged with more than one dance. So some of my songs are "Discofox" as well as "Cha Cha". The abbreviation field should show "DF - CC" for that cases.

Is it possible to create such a field? Thanks for any input :)
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42053
  • Shoes gone again!
Re: [Expression] Merging field values into one field
« Reply #1 on: April 22, 2015, 08:14:11 am »

IfElse is the only way I think you could do it because you've got complicated rules that decide what the proper abbreviation should be. 

If you always just took the first two letters, you could do that with an expression but it sounds like you've got bigger plans.
Logged
Matt Ashland, JRiver Media Center

StFeder

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1493
  • Fight! You may win. If you don't, you already lost
Re:
« Reply #2 on: April 22, 2015, 08:20:25 am »

But IfElse stops after finding the first hit, doesn't it? So it won't find a second or even third hit?! If I don't miss a thing, it will not work.

Anyway: thanks for your feedback! Didn't think this would be complicated. So I finally know I'm not to dumb :)
Logged

gappie

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 4566
Re: [Expression] Merging field values into one field
« Reply #3 on: April 22, 2015, 09:47:40 am »

would using the Replace expression together with the ListBuild expression be an idea?

Listbuild(1,-,Replace([Dance], Tango, TG),Replace([Dance], Slow Waltz, SW),etc)


i did not test it.

 :)
gab


edit: i tested it now and it does not work.
but this does Replace(Replace(Replace([Dance], Tango, TG),Slow Waltz,SW),Cha Cha,CC)
im not sure if it is of any use.  8)
Logged

StFeder

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1493
  • Fight! You may win. If you don't, you already lost
Re: [Expression] Merging field values into one field
« Reply #4 on: April 23, 2015, 10:29:11 am »

Here is how I got it working finally:
I have a master field Dance which lists all valid dances for the given song. I created a field for every single dance. So I got ~20 fields Named Dance Abbreviation 1, Dance Abbreviation 2, and so on. Every field is calculated to just look for ONE dance inside Dance. It stays empty if it doesn't find this dance and outputs the abbreviation followed by ", " if it does. Then there is a second field called Abbreviation wich just lists all abbreviations but removes the last two digits, so the last ", " isn't included in the output.

So it looks like this:

Field NameField code
Abbreviation SWIf(IsEqual([Dance], Slow Waltz, 8),SW/, ,)
Abbreviation SBIf(IsEqual([Dance], Samba, 8),SB/, ,)
...
Abbreviationremoveright([Abbreviation SW][Abbreviation SB] ... ,2)


but this does Replace(Replace(Replace([Dance], Tango, TG),Slow Waltz,SW),Cha Cha,CC)

This indeed does a nice job! The differences between your and my implementation are:

  • if Dance contains something I didn't consider in my list (eg. Bachata) it will be displayed if I use your suggestion and it won't if I use mine.
  • Using my implementation I'm able to sort the abbreviations the way I want, instead of getting them sort as they are presented in Dance.
  • well, don't know how important it is (at least for my use) but your suggestion just needs one field, I currently need ~20.

I don't know which one I will use finally, but I guess it could be easier to mess around with one giant field instead of messing around with ~20.

Thank you for taking the time to point me to this direction! Didn't know about the replace function (although I was looking for something like this in the wiki...).
Logged

gappie

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 4566
Re: [Expression] Merging field values into one field [solved]
« Reply #5 on: April 23, 2015, 11:24:53 am »

i see... :)
i do think though, that for your solution you dont need to make so much fields. i think one would be enough

removeright(If(IsEqual([Dance], Slow Waltz, 8),SW/, ,)If(IsEqual([Dance], Samba, 8),SB/, ,)If(IsEqual([Dance], Tango, 8),TG/, ,)..... ,2)

 :)
gab

edit.. cool those  8)
but the idea is
Code: [Select]
removeright(If(IsEqual([Dance], Slow Waltz, 8),SW/, ,)If(IsEqual([Dance], Samba, 8),SB/, ,)If(IsEqual([Dance], Tango, 8),TG/, ,)..... ,2)
Logged

StFeder

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1493
  • Fight! You may win. If you don't, you already lost
Re: [Expression] Merging field values into one field [solved]
« Reply #6 on: April 24, 2015, 09:21:42 am »

You are right. I deleted all fields and merged everything into one. And I changed to the use of the replace tag you suggested in your previous post. It's nice to have values of my Dance field displayed even when I didn't integrate a given value into my expression. Although the super long replace expression is bit more difficult to handle because of the more nested structure.

Thanks for your kind assistance, gab. Not the first time you helped me out when was trying to optimize MC for my ballroom needs...

Code: [Select]
removeright(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace([Tanz], Boogie, BG/, ), Blues, BL/, ), Cha Cha, CC/, ), Discofox, DF/, ), Foxtrott, FX/, ), Jive, JI/, ), Langsamer Walzer, LW/, ), Nightclub, NCTS/, ), Paso Doble, PD/, ), Quickstep, QS/, ), Rock'n'Roll, RnR/, ), Rumba, RB/, ), Samba, SB/, ), Slowfox, SF/, ), Tango Argentino, TG Arg/, ), Tango, TG/, ), West Coast Swing, WCS/, ), Wiener Walzer, WW/, ), &,), ;,),1)
BTW: Just in case you didn't know about this handy option: to get rid of those cool sunglass smilies, check the "Additional Options..." right beneath the text posts input window. Not only the cool once will disappear, but also the once that always wanna make us cry :'(
Logged

gappie

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 4566
Re: [Expression] Merging field values into one field [solved]
« Reply #7 on: April 25, 2015, 03:03:56 am »

youre welcome, and thanks for the tip. i did not know that.

 :)
gab
Logged
Pages: [1]   Go Up