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
Datagulf
Responsive Resident
Responsive Resident

Create DAX/ Power Query column from a column with different items

I want to create a column from another column. The column has Numerical values and Text Values hence can only be stored in text values. The column is as follows and the column next to it is my ask. 

Item Code  Desired Column
100000 Item

100001

 Item
100002 Item
100003 Item
100004 Item
100005 Item
6000000 Parts
6000001 Parts
6000002 Parts
6000003 Parts
6000004 Parts
LABOUR Labour
LABOUR Labour

 

The items range is 100000 to 100117 and the Parts range is 6000000 to 6000234. LABOUR is just Labour.

1 ACCEPTED SOLUTION

Hi @Datagulf ,

 

You can try this method:

New a column:

Desired Column =
IF (
    MID ( 'Table'[Item Code ], 1, 3 ) = "100",
    "Item",
    IF ( MID ( 'Table'[Item Code ], 1, 3 ) = "600", "Parts", "Labour" )
)

The result is:

vyinliwmsft_0-1669182705545.png

 

Hope this helps you.

Here is my PBIX file.

 

Best Regards,

Community Support Team _Yinliw

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

3 REPLIES 3
mangaus1111
Solution Sage
Solution Sage

Hi @Datagulf ,

 

add a conditional column  using this code

 

#"Added Conditional Column" = Table.AddColumn(#"Removed Top Rows", "Custom", each if Text.StartsWith([#"Item Code "], "1") then "Item" else if Text.StartsWith([#"Item Code "], "6") then "Parts" else "Labour")

 

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

The startswith is not working for me. It  brings an error..

Datagulf_0-1669138661372.png

@mangaus1111 

Datagulf_1-1669138968134.png

 

Hi @Datagulf ,

 

You can try this method:

New a column:

Desired Column =
IF (
    MID ( 'Table'[Item Code ], 1, 3 ) = "100",
    "Item",
    IF ( MID ( 'Table'[Item Code ], 1, 3 ) = "600", "Parts", "Labour" )
)

The result is:

vyinliwmsft_0-1669182705545.png

 

Hope this helps you.

Here is my PBIX file.

 

Best Regards,

Community Support Team _Yinliw

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

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.