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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Mike_T
New Member

Problem splitting column with delimiter

Hi,

 

I have split the column "Fldvalue" based on the delimiter " | ". See table: The third and fourth column of the sample have been split. 

 

IDFldnameFldvalue.1Fldvalue.2
1267A_employeeTeam_Option|SalesPeter
1267B_managerString_Option|CommerceManager Dudley
1267C_subjectDescription A 
7654A_employeeTeam_Option|PurchaseJohn
3489A_employeeTeam_Option|SalesPeter
3489B_managerString_Option|MarketingManager Michele
3489C_subjectDescription B 
2367A_employeeTeam_Option|PurchaseMandy
2367B_managerString_Option|MarketingManager Michele
2367C_subjectDescription C 
6812A_employeeTeam_Option|PurchaseJohn
6812B_managerString_Option|CommerceManager Blake
6812C_subjectDescription D 

 

Unfortunately, not alle values in the original column have the "|" delimiter. The result is that some values in column Fldvalue.2 are empty. If you look more closely, it concerns the values of "C-subject" in Column Fldname.

 

I want column Fldvalue.2 to show all values, including the values of "C-subject". Is it possible with query editor/DAX to move the values for variable "C_ subject" from column Fldvalue.1 to Fldvalue.2?

 

Thanks in advance.

Mike

 

2 ACCEPTED SOLUTIONS
Jimmy801
Community Champion
Community Champion

Hello @Mike_T 

 

or you change your dataset and place there the limiter two times or you apply two time Table.ReplaceValue. Here an example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZI/D4IwEMW/CunMIirgyJ/JhEiCGyGk1ougbSFtGUj88BZE0gUS3Hov97u+d7k8RzvH9ZCNghJYS5seQBdXwKy8tKpu+DvDFKTWUlAgUGHPRFgyzPFDizbKlKj544dEDWMgyDAp+bZYcXen0Jt4VMru9gSi9DsGSUQ9wlaga2ts9NzjYc1Z2glSYTnI56biI7M/+KdtaSZiOU2CxQuUFow4SU0qoGAOWMoTznmc/fqmjTz6n3tvQv/bmwYs2Ytme66/c7aue2I2nUJI8QtMesla/LVWfAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Fldname = _t, Fldvalue.1 = _t, Fldvalue.2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Fldname", type text}, {"Fldvalue.1", type text}, {"Fldvalue.2", type text}}),

    Replace = Table.ReplaceValue
    (
        #"Changed Type",
        each [#"Fldvalue.2"], 
        (row)=> if row[Fldname]="C_subject" then row[#"Fldvalue.1"] else row[#"Fldvalue.2"] ,
        Replacer.ReplaceValue,
        { "Fldvalue.2"}
    ),
    Replace2 = Table.ReplaceValue
    (
        Replace,
        each [#"Fldvalue.1"], 
        (row)=> if row[Fldname]="C_subject" then "" else row[#"Fldvalue.1"] ,
        Replacer.ReplaceValue,
        { "Fldvalue.1"}
    )
in
    Replace2

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

 

View solution in original post

v-xuding-msft
Community Support
Community Support

Hi @Mike_T ,

 

= Table.AddColumn(#"Changed Type", "Custom", each if [Fldvalue.2] = "" then [Fldvalue.1] else [Fldvalue.2])
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZI/C4MwEMW/imR2qVq1o3+mglSwm4ik6aGpiZYYB6EfvtFqyWLBbrnH/S7vHZfn6GC5HjJRUAJ/sm4EUMUVMC8vT0m79pVhBr3SUpAgUGF+ibDkuMWVEk2USUHbakWijnMQZJqUfFqMeLgzGHU8Kvvh9gAi1TuGngg6w0ag6rnPc4/OL2PpIEiN+0k+d3U7M7bjn/aFWYjtMAkWDUglaGkSSmpgoA/YihOucSz79561OOqb+6hD/7tbBmy5i1Z3rn+w9i57YXbdQchwAzq95SyenRVv", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Fldname = _t, Fldvalue.1 = _t, Fldvalue.2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Fldname", type text}, {"Fldvalue.1", type text}, {"Fldvalue.2", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Fldvalue.2] = "" then [Fldvalue.1] else [Fldvalue.2]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Fldvalue.2"})
in
    #"Removed Columns"

v-xuding-msft_0-1602487503771.png

 

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-xuding-msft
Community Support
Community Support

Hi @Mike_T ,

 

= Table.AddColumn(#"Changed Type", "Custom", each if [Fldvalue.2] = "" then [Fldvalue.1] else [Fldvalue.2])
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZI/C4MwEMW/imR2qVq1o3+mglSwm4ik6aGpiZYYB6EfvtFqyWLBbrnH/S7vHZfn6GC5HjJRUAJ/sm4EUMUVMC8vT0m79pVhBr3SUpAgUGF+ibDkuMWVEk2USUHbakWijnMQZJqUfFqMeLgzGHU8Kvvh9gAi1TuGngg6w0ag6rnPc4/OL2PpIEiN+0k+d3U7M7bjn/aFWYjtMAkWDUglaGkSSmpgoA/YihOucSz79561OOqb+6hD/7tbBmy5i1Z3rn+w9i57YXbdQchwAzq95SyenRVv", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Fldname = _t, Fldvalue.1 = _t, Fldvalue.2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Fldname", type text}, {"Fldvalue.1", type text}, {"Fldvalue.2", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Fldvalue.2] = "" then [Fldvalue.1] else [Fldvalue.2]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Fldvalue.2"})
in
    #"Removed Columns"

v-xuding-msft_0-1602487503771.png

 

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Jimmy801
Community Champion
Community Champion

Hello @Mike_T 

 

or you change your dataset and place there the limiter two times or you apply two time Table.ReplaceValue. Here an example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZI/D4IwEMW/CunMIirgyJ/JhEiCGyGk1ougbSFtGUj88BZE0gUS3Hov97u+d7k8RzvH9ZCNghJYS5seQBdXwKy8tKpu+DvDFKTWUlAgUGHPRFgyzPFDizbKlKj544dEDWMgyDAp+bZYcXen0Jt4VMru9gSi9DsGSUQ9wlaga2ts9NzjYc1Z2glSYTnI56biI7M/+KdtaSZiOU2CxQuUFow4SU0qoGAOWMoTznmc/fqmjTz6n3tvQv/bmwYs2Ytme66/c7aue2I2nUJI8QtMesla/LVWfAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Fldname = _t, Fldvalue.1 = _t, Fldvalue.2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Fldname", type text}, {"Fldvalue.1", type text}, {"Fldvalue.2", type text}}),

    Replace = Table.ReplaceValue
    (
        #"Changed Type",
        each [#"Fldvalue.2"], 
        (row)=> if row[Fldname]="C_subject" then row[#"Fldvalue.1"] else row[#"Fldvalue.2"] ,
        Replacer.ReplaceValue,
        { "Fldvalue.2"}
    ),
    Replace2 = Table.ReplaceValue
    (
        Replace,
        each [#"Fldvalue.1"], 
        (row)=> if row[Fldname]="C_subject" then "" else row[#"Fldvalue.1"] ,
        Replacer.ReplaceValue,
        { "Fldvalue.1"}
    )
in
    Replace2

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors