Forum Discussion

raghukumarch's avatar
raghukumarch
Frequent Visitor
4 years ago
Solved

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.

 

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

  • 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

     

    New Column Name: CheckColumn

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

    Now click on OK.

     

    Now again click on  Add Column - > Custom Column

     

    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.

     

     

    Here's the desire output in a new column.

     

     

     

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

2 Replies

  • 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

     

    New Column Name: CheckColumn

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

    Now click on OK.

     

    Now again click on  Add Column - > Custom Column

     

    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.

     

     

    Here's the desire output in a new column.

     

     

     

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