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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
raghukumarch
Frequent Visitor

DAX Help for Custom/Conditional Column

Hi, 

Could you please help me in achieving this either in DAX or PowerQuery.
One of my column in table has values like this.

raghukumarch_0-1660668513612.png

 

I wanted to create another column in same table by adding "0" in the begining for the values which dose not contain "-" and other value which contains "-" should remains same as it is. 

For example column 'C_SerialNumber' have values like "311211025073516" and "916429-19-11"

I wanted to add '0' in the begining if the value DOES NOT Contain '-'. So the output will be "0311211025073516" and other values remains same.

 

Thanks

RK

1 ACCEPTED SOLUTION
bilalrana
Resolver I
Resolver I

Dear @raghukumarch ,

I have implemented your scenario, Here's the few steps to achieve the required output.

Go to Home - > Transform Data 

 

Open the Query which contains the column C_SerialNumber.

Go to - > Add Column - > Custom Column

bilalrana_0-1660733717145.png

 

New Column Name: CheckColumn

Custom column formula: Text.Contains([C_SerialNumber],"-")

Now click on OK.

 

Now again click on  Add Column - > Custom Column

bilalrana_1-1660733717150.png

 

New Column Name: NewC_SerialNumber

Custom column formula: if [CheckColumn] = false then "0" & [C_SerialNumber] else [C_SerialNumber]

Now click on OK.

Now, check on the formula bar, if the type isn't set to text then write it in a way as below screen short and click on the tick.

bilalrana_2-1660733717160.png

 

 

Here's the desire output in a new column.

bilalrana_3-1660733717155.png

 

 

 

Please like the reply and accept it as a solution to help the Power BI Community.

View solution in original post

2 REPLIES 2
bilalrana
Resolver I
Resolver I

Dear @raghukumarch ,

I have implemented your scenario, Here's the few steps to achieve the required output.

Go to Home - > Transform Data 

 

Open the Query which contains the column C_SerialNumber.

Go to - > Add Column - > Custom Column

bilalrana_0-1660733717145.png

 

New Column Name: CheckColumn

Custom column formula: Text.Contains([C_SerialNumber],"-")

Now click on OK.

 

Now again click on  Add Column - > Custom Column

bilalrana_1-1660733717150.png

 

New Column Name: NewC_SerialNumber

Custom column formula: if [CheckColumn] = false then "0" & [C_SerialNumber] else [C_SerialNumber]

Now click on OK.

Now, check on the formula bar, if the type isn't set to text then write it in a way as below screen short and click on the tick.

bilalrana_2-1660733717160.png

 

 

Here's the desire output in a new column.

bilalrana_3-1660733717155.png

 

 

 

Please like the reply and accept it as a solution to help the Power BI Community.

Greg_Deckler
Community Champion
Community Champion

@raghukumarch Maybe:

DAX Column = 
  IF(FIND("-",[C_SerialNumber],,-1) = -1, "0" & [C_SerialNumber], [C_SerialNumber])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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