Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Calculated column using IF and OR statements (or SWITCH?)

Hello,

I'm trying to create a calculated column based on an existing column and using IF and OR statements to change 3 values. It doesn't seem to work if I have different if values. I even tried SWITCH but it doesn't seem to work with a column as the <else> value.

 

FA = SWITCH(TRUE(), 'ProgramIntermediate'[Project ID]="50323" && 'ProgramIntermediate'[Project ID]="50279","Project A", 'ProgramIntermediate'[Project ID]="12347" && 'ProgramIntermediate'[Project ID]="12347","Affiliate" -'ProgramIntermediate'[Focus Area])
 
'ProgramIntermediate'[Focus Area] is the existing column I want to replicate
I want to change the values of the column to "Project A" if the ID is 50323 and 50279 and change the value to "Affiliate" if the ID is 12347 and 12347.
 
Any ideas? Thanks!
1 ACCEPTED SOLUTION
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

Not sure if I understand it correctly, if Project ID = 50323 or 50279 then Project A else if Project ID = 12347 then Affiliate else Focus Area? As you have 12347 twice, so just put one...

 

FA =
SWITCH (
    TRUE (),
    'ProgramIntermediate'[Project ID] = "50323"
        || 'ProgramIntermediate'[Project ID] = "50279", "Project A",
    'ProgramIntermediate'[Project ID] = "12347", "Affiliate",
    'ProgramIntermediate'[Focus Area]
)

 

View solution in original post

3 REPLIES 3
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

Not sure if I understand it correctly, if Project ID = 50323 or 50279 then Project A else if Project ID = 12347 then Affiliate else Focus Area? As you have 12347 twice, so just put one...

 

FA =
SWITCH (
    TRUE (),
    'ProgramIntermediate'[Project ID] = "50323"
        || 'ProgramIntermediate'[Project ID] = "50279", "Project A",
    'ProgramIntermediate'[Project ID] = "12347", "Affiliate",
    'ProgramIntermediate'[Focus Area]
)

 

Anonymous
Not applicable

Sorry, @Vera_33  I made a typo. It's actually 4 values:

FA = SWITCH(TRUE(), 'ProgramIntermediate'[Project ID]="50323" && 'ProgramIntermediate'[Project ID]="50279","Project A", 'ProgramIntermediate'[Project ID]="50316" && 'ProgramIntermediate'[Project ID]="50381","Affiliate",'ProgramIntermediate'[Focus Area])
 
Yes, the logic is if Project ID is 50323 and 50279, then Project A; if Project ID is 50316 and 50381, then Affiliate, else Focus Area. I tried the above and it didn't do anything. It's no longer an error, but it just replicated all the Focus Area values and nothing was changed.
Anonymous
Not applicable

Oh wait,  i didn't change the && to II. It worked! Thank you!!!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.