Text combine

hnorgaar

New Member
Joined
Jul 21, 2018
Messages
31
Office Version
  1. 2019
Platform
  1. Windows
Hi

Im trying to combine 3 fields like textjoin

Motor is always not empty, both engine type and HK can be empty. So Motor + EngineType if it contains "Turbo" then "Turbo" else empty and if HK is not empty then + HK + "HK" divided by spaces

And this gives me an error and is missing "HK" in the end
Text.Combine({[Motor], Text.Contains([EngineType], "Turbo", "Turbo"), [HK]}, " ")

result like this "320 xDrive Turbo 125HK" if all is not empty

Thx in advance Henrik
 
Last edited:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I am not entirely sure about the conditions and the desired output, but the following should provide some information:

The source range:
MotorEngineTypeHK
MotorAEngıneA
MotorBEngıneB Turbo
MotorC TurboHKC
MotorDEngineDHKD


The Power Query M Code:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Custom = Table.AddColumn(Source, "Custom", each Text.Combine({_[Motor], if Text.Contains(_[Motor] & Text.From(_[EngineType]), "Turbo")??false then "Turbo" else "", Text.From(_[HK])}, " "))
in
    Custom

The result:
MotorEngineTypeHKCustom
MotorAEngıneAMotorA
MotorBEngıneB TurboMotorB Turbo
MotorC TurboHKCMotorC Turbo HKC
MotorDEngineDHKDMotorD HKD

If this doesn't generate the output you want, then please provide sample data as my source range above, so I can modify the code as necessary.
 
Upvote 0
Solution
I am not entirely sure about the conditions and the desired output, but the following should provide some information:

The source range:
MotorEngineTypeHK
MotorAEngıneA
MotorBEngıneB Turbo
MotorC TurboHKC
MotorDEngineDHKD


The Power Query M Code:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Custom = Table.AddColumn(Source, "Custom", each Text.Combine({_[Motor], if Text.Contains(_[Motor] & Text.From(_[EngineType]), "Turbo")??false then "Turbo" else "", Text.From(_[HK])}, " "))
in
    Custom

The result:
MotorEngineTypeHKCustom
MotorAEngıneAMotorA
MotorBEngıneB TurboMotorB Turbo
MotorC TurboHKCMotorC Turbo HKC
MotorDEngineDHKDMotorD HKD

If this doesn't generate the output you want, then please provide sample data as my source range above, so I can modify the code as necessary.
Thats working fine, just missing 1 step, checking for HK is not empty then add "HK" in the end of the text
Thx
Henrik
 
Upvote 0
Please try the following version.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Custom = Table.AddColumn(Source, "Custom", 
        each Text.Combine(
            {
                _[Motor], 
                if Text.Contains(_[Motor] & Text.From(_[EngineType]), "Turbo")??false then "Turbo" else "", 
                if Text.From(_[HK]) <> "" then Text.From(_[HK]) & " HK" else ""
            }, " "))
in
    Custom
 
Upvote 0
Please try the following version.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Custom = Table.AddColumn(Source, "Custom",
        each Text.Combine(
            {
                _[Motor],
                if Text.Contains(_[Motor] & Text.From(_[EngineType]), "Turbo")??false then "Turbo" else "",
                if Text.From(_[HK]) <> "" then Text.From(_[HK]) & " HK" else ""
            }, " "))
in
    Custom
Hi, yes I figured that out myself and all good now, but thanks for your input, appreciate it
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,609
Members
452,660
Latest member
Zatman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top