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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
bhargavanand
Helper I
Helper I

fill column based on other column values

Hi,

 

I have two columns which Code and Names. I want to add a calculated column which should be assigned a number based on a condition that
if Code = A and Name = B then 1,

if Code = C and Name = D then 2,

if Code = E and Name = F then 3,

if Code = G and Name = H then 4

 

bhargavanand_0-1718653748772.png

 

 

How can I implement this in Power BI?


Thanks in advance.

1 ACCEPTED SOLUTION
foodd
Super User
Super User

 

CalculatedColumn =
SWITCH(
    TRUE(),
    'Table'[Code] = "A" && 'Table'[Names] = "B", 1,
    'Table'[Code] = "C" && 'Table'[Names] = "D", 2,
    'Table'[Code] = "E" && 'Table'[Names] = "F", 3,
    'Table'[Code] = "G" && 'Table'[Names] = "H", 4,
    BLANK()
)
 

foodd_0-1718655025404.png

 

If your requirement is solved, please make THIS ANSWER a SOLUTION ✔️ and help other users find the solution quickly. Please hit the LIKE 👍 button if this comment helps you.

View solution in original post

2 REPLIES 2
foodd
Super User
Super User

Hello @bhargavanand .   Thank you for finding my suggestion a Solution for your need.  Please hit the LIKE 👍 button if it has helped you.

foodd
Super User
Super User

 

CalculatedColumn =
SWITCH(
    TRUE(),
    'Table'[Code] = "A" && 'Table'[Names] = "B", 1,
    'Table'[Code] = "C" && 'Table'[Names] = "D", 2,
    'Table'[Code] = "E" && 'Table'[Names] = "F", 3,
    'Table'[Code] = "G" && 'Table'[Names] = "H", 4,
    BLANK()
)
 

foodd_0-1718655025404.png

 

If your requirement is solved, please make THIS ANSWER a SOLUTION ✔️ and help other users find the solution quickly. Please hit the LIKE 👍 button if this comment helps you.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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