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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
ericdpalmer
Frequent Visitor

Custom Column to convert an ID text string to a text Value (SWITCH function?)

To overcome a database bug I need to filter my data by a 36 character 'ID' field but the executive audience for my report wants to see the corresponding 'Value' (aka. Name) of each on the Report Slicer.  After some light googling/searching on this forum I attempted to create a new custom column that would utilize the SWITCH function.

 

Example of my goal:

Existing Column "PlanType_EnterpriseProject_ID" returns = aad0e900-ae1c-435b-b3b7-0be5242539fb

New Custom Column "PlanType_EnterpriseProject_IDtoValue" returns = Improve Processess, Systems, and Infrastructure


Here is my attempt at creating the custom column:

=SWITCH( [PlanType_EnterpriseProject_Id], "aad0e900-ae1c-435b-b3b7-0be5242539fb", "Improve Processess, Systems, and Infrastructure", "b85b8606-1972-4f63-ace2-1a9e0f8bf195", "Optimize Core Products", "81b6abcb-8488-47e7-8d26-5f36de8fd2a3", "Build a High Performing Team", "fd8cabb0-f2ad-4ec6-b59f-76aeedb0dde2", "Coach People to Prosperity", "aa290c8f-a1e9-4dc3-8017-259d09bb411e", "Enterprise Facilities Projects", "b234318e-11aa-469b-b080-d0c4d93079da", "Test Portfolio")

This was the error message:

ericdpalmer_0-1679428274585.png


I am still very early in my Power BI journey so I'm sure there is something simple I'm missing or didn't search for the appropriate criteria.  Any help is appreciated!  

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @ericdpalmer 

 

Download example PBIX file

 

SWITCH is a DAX function and can't be used in Power Query, which is where you are trying to write the formula shown in your screenshot.

 

In Power Query you will need to use nested if functions.  Or you can do this in DAX too using SWITCH.

 

In Power Query you create the column like this 

 

 

if [PlanType_EnterpriseProject_ID] = "aad0e900-ae1c-435b-b3b7-0be5242539fb" then "Improve Processess, Systems, and Infrastructure"

else if [PlanType_EnterpriseProject_ID] = "b85b8606-1972-4f63-ace2-1a9e0f8bf195" then "Optimize Core Products" 

else if [PlanType_EnterpriseProject_ID] = "81b6abcb-8488-47e7-8d26-5f36de8fd2a3" then "Build a High Performing Team"

else if [PlanType_EnterpriseProject_ID] = "fd8cabb0-f2ad-4ec6-b59f-76aeedb0dde2" then "Coach People to Prosperity" 

else if [PlanType_EnterpriseProject_ID] = "aa290c8f-a1e9-4dc3-8017-259d09bb411e" then "Enterprise Facilities Projects" 

else if [PlanType_EnterpriseProject_ID] = "b234318e-11aa-469b-b080-d0c4d93079da" then "Test Portfolio" 

else null 

 

 

 

To create the column in DAX (after loading the data from Power Query into Power BI) you can write this

 

 

DAX Column = SWITCH(

    [PlanType_EnterpriseProject_Id],

    "aad0e900-ae1c-435b-b3b7-0be5242539fb", "Improve Processess, Systems, and Infrastructure", 
    
    "b85b8606-1972-4f63-ace2-1a9e0f8bf195", "Optimize Core Products", 
    
    "81b6abcb-8488-47e7-8d26-5f36de8fd2a3", "Build a High Performing Team", 
    
    "fd8cabb0-f2ad-4ec6-b59f-76aeedb0dde2", "Coach People to Prosperity", 
    
    "aa290c8f-a1e9-4dc3-8017-259d09bb411e", "Enterprise Facilities Projects", 
    
    "b234318e-11aa-469b-b080-d0c4d93079da", "Test Portfolio",

    "Not Found"

)

 

 

Note that SWITCH requires a default result which in my function above is the last line that returns "Not Found".  This default is in case none of the preceding conditions are met (found to be true).

 

The Power Query if is similar in that it requires a final else statement, which I have used to output null if none of the ID's are found.  

 

See attached file for examples of both.

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

2 REPLIES 2
PhilipTreacy
Super User
Super User

Hi @ericdpalmer 

 

Download example PBIX file

 

SWITCH is a DAX function and can't be used in Power Query, which is where you are trying to write the formula shown in your screenshot.

 

In Power Query you will need to use nested if functions.  Or you can do this in DAX too using SWITCH.

 

In Power Query you create the column like this 

 

 

if [PlanType_EnterpriseProject_ID] = "aad0e900-ae1c-435b-b3b7-0be5242539fb" then "Improve Processess, Systems, and Infrastructure"

else if [PlanType_EnterpriseProject_ID] = "b85b8606-1972-4f63-ace2-1a9e0f8bf195" then "Optimize Core Products" 

else if [PlanType_EnterpriseProject_ID] = "81b6abcb-8488-47e7-8d26-5f36de8fd2a3" then "Build a High Performing Team"

else if [PlanType_EnterpriseProject_ID] = "fd8cabb0-f2ad-4ec6-b59f-76aeedb0dde2" then "Coach People to Prosperity" 

else if [PlanType_EnterpriseProject_ID] = "aa290c8f-a1e9-4dc3-8017-259d09bb411e" then "Enterprise Facilities Projects" 

else if [PlanType_EnterpriseProject_ID] = "b234318e-11aa-469b-b080-d0c4d93079da" then "Test Portfolio" 

else null 

 

 

 

To create the column in DAX (after loading the data from Power Query into Power BI) you can write this

 

 

DAX Column = SWITCH(

    [PlanType_EnterpriseProject_Id],

    "aad0e900-ae1c-435b-b3b7-0be5242539fb", "Improve Processess, Systems, and Infrastructure", 
    
    "b85b8606-1972-4f63-ace2-1a9e0f8bf195", "Optimize Core Products", 
    
    "81b6abcb-8488-47e7-8d26-5f36de8fd2a3", "Build a High Performing Team", 
    
    "fd8cabb0-f2ad-4ec6-b59f-76aeedb0dde2", "Coach People to Prosperity", 
    
    "aa290c8f-a1e9-4dc3-8017-259d09bb411e", "Enterprise Facilities Projects", 
    
    "b234318e-11aa-469b-b080-d0c4d93079da", "Test Portfolio",

    "Not Found"

)

 

 

Note that SWITCH requires a default result which in my function above is the last line that returns "Not Found".  This default is in case none of the preceding conditions are met (found to be true).

 

The Power Query if is similar in that it requires a final else statement, which I have used to output null if none of the ID's are found.  

 

See attached file for examples of both.

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Thank you so much!  Not only did this solve my issue but I have a much better understanding.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.