Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago

Switch Column Logic Help

Hi All,

 

I'm in a pickle. I have the below logic using 3 columns on the same table:

 

Label = Switch(
True(),
ActiveHC[Country Name] = "Turkey", "Cars",
ActiveHC[Country Name] = "Greece", "Cars",
ActiveHC[Country Name] = "Italy", "Cars",
ActiveHC[Layer 2] = "Beth", "Corporate",
ActiveHC[Layer 2] = "Joanie", "Corporate",
ActiveHC[Layer 2] = "Dan", "Corporate",
ActiveHC[Layer 2] = "Bill", "Corporate",
ActiveHC[Layer 2] = "Christina", "Corporate",
ActiveHC[Layer 2] = "Steven", "Cars",
ActiveHC[Layer 2] = "Bobby", "Audio",
ActiveHC[Layer 2] = "Matt", "Photos",
ActiveHC[Layer 2] = "Peter", "Photos",
ActiveHC[Layer 2] = "Edward", "Photos",
ActiveHC[Layer 2] = "Joey", "Software",
ActiveHC[Business Unit] = "Cameras", "Cameras",
Blank()
)
 
All of these people listed above have employees under them in Turkey, Greece, and Italy. What I need to happen is that if ANY of of these leaders have employees in those countries, I need the label "Cars" to supercede the additional labels I've given. Does that make sense? So for example, if Edward has 5 employees that are in those countries, I want them to be labeled Cars instead of Photos because the country needs to trump the alternate label I'm giving. I basically need everything to go into 1 column. 
 
I tried using some VAR logic, but just wasn't getting the right result. I'm probably over complicating it!  Any help would be great please.
 

14 Replies

  • AlB's avatar
    AlB
    Community Champion

    Hi Anonymous 

    Since the condition on the number of employees supersedes all others, I would do something like the following, where [NumberOfEmployees] is whatever piece of code you use to know the number of employees under the leader in Greece, Italy, Turkey.

    Label =
    IF (
        [NumberOfEmployees] > 0,
        "Cars",
        SWITCH (
            TRUE (),
            ActiveHC[Country Name] = "Turkey", "Cars",
            ActiveHC[Country Name] = "Greece", "Cars",
            ActiveHC[Country Name] = "Italy", "Cars",
            ActiveHC[Layer 2] = "Beth", "Corporate",
            ActiveHC[Layer 2] = "Joanie", "Corporate",
            ActiveHC[Layer 2] = "Dan", "Corporate",
            ActiveHC[Layer 2] = "Bill", "Corporate",
            ActiveHC[Layer 2] = "Christina", "Corporate",
            ActiveHC[Layer 2] = "Steven", "Cars",
            ActiveHC[Layer 2] = "Bobby", "Audio",
            ActiveHC[Layer 2] = "Matt", "Photos",
            ActiveHC[Layer 2] = "Peter", "Photos",
            ActiveHC[Layer 2] = "Edward", "Photos",
            ActiveHC[Layer 2] = "Joey", "Software",
            ActiveHC[Business Unit] = "Cameras", "Cameras",
            BLANK ()
        )
    )
    

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi AlB,

       

      Thanks so much for this. However, I added additional context. Just can't seem to get this to work. :( 

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Greg_Deckler & AlB 

      Thanks for the feedback. I have pasted sample data below:

      EE IDCountryDivisionLayer 1Layer 2
      5464ItalyCamerasPaulBeth
      5221GreeceCarsPaulJoanie
      5845TurkeyCarsPaulDan
      231132TurkeyCorporatePaulBill
      112258GreeceCorporatePaulChristina
      5843USACarsPaulSteven
      123USAImagingPaulJacob
      46546USAPhotosPaulMatt
      12132468SwedenAudioPaulPeter
      546544MonacoCorporatePaulEdward
      13132FranceSoftwarePaulJoey
      12132ItalyAudioPaulBobby



      Regarding my original post, I want to create a calculated column called "Label". The layer 2 name should return the result of what I have outlined above in my original post. However, if the country is ITALY, GREECE or TURKEY, then I want it to be called "CARS" regardless of that person's name and desired value I outlined above. I essentially want the country to take over the label from the switch function and that if those 3 countries are NOT mentioned then it gives me the label that I have outlined above -- please note that Steven is also in charge of "Cars" though he is in the USA, which is fine. 

       

      As you can see from the original post, Bobby would be audio, but since he has headcount in Italy, I would want Cars to be the label instead since he has headcount in Italy. The final table should look like this:

       

      LabelCount
      Cars7
      Imaging1
      Audio1
      Corporate1
      Software1
      Photos1

       

      I also want to use this as a field to put into a bigger data table for records export so that it looks like this:

      EE IDCountryDivisionLayer 1Layer 2Label
      5464ItalyCamerasPaulBethCars
      5221GreeceCarsPaulJoanieCars
      5845TurkeyCarsPaulDanCars
      231132TurkeyCorporatePaulBillCars
      112258GreeceCorporatePaulChristinaCars
      5843USACarsPaulStevenCars
      123USAImagingPaulJacobImaging
      46546USAPhotosPaulMattPhotos
      12132468SwedenAudioPaulPeterAudio
      546544MonacoCorporatePaulEdwardCorporate
      13132FranceSoftwarePaulJoeySoftware
      12132ItalyAudioPaulBobbyCars

       

      I hope this helps! Thanks so much all!!!!

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Greg_Deckler,

         

        I was wondering if you had any additional insight on this now that I provided additional data. Leaving today on vacation through Monday. Been coming up dry :( 

         

        I tried doing some Var = logic, but no luck. 

         

        Many thanks as always.