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
Anupal
Frequent Visitor

DAX to Create 2 Custom columns based on a selected value

Hello Members,

 

I am looking help with a DAX to create2 custom columns based on inputs from original field.

 

there are mulitple values in the field which- 1)- have to grouped based on a filter calue and then 2)- 2 custom fields to be created based on that grouping and filter value-

 

Eg: Below-

Current Input ColumnExpected 2 custom Columns
Input FieldOutput Field_1Output Field_2
AAAAA;BBBBBBValues Values based on AAAAAValues Values based on BBBBBB
AAAAAA;CCCCCC
AAAAA;DDDDDD
BBBBBB;EEEEEEE
FFFFFFFF;HHHHHHH
HHHHHHH;GGGGGG

 

Here my Input(actual field has certain text values.

Now i want to create 2 fields based on criteria where Values contain AAAAA and BBBBB

 

So 2 fields needs tobe created, one will provide only values containing AAAAA and other field will provide values containing BBBBB

 

How can this be achived.

 

Thanks

AP

2 ACCEPTED SOLUTIONS
Dangar332
Super User
Super User

hi, @Anupal 

 

Add two columns in your current table
try below column code

 

 

outpu_field1=
VAR a = SEARCH(";",'Table (2)'[Current Input Column])
return
LEFT('Table (2)'[Current Input Column],a-1)

 

 

 

 

 

output_field2=
VAR a = SEARCH(";",'Table (2)'[Current Input Column])
var b = LEN('Table (2)'[Current Input Column])
return
RIGHT('Table (2)'[Current Input Column],b-a)

 

 

and it easy in power query

use split column

Dangar332_0-1709619482878.png

 

 

View solution in original post

Anonymous
Not applicable

Hi @Anupal 

 

@Dangar332 , thanks for your contribution to the forum

Just as he posted that you can add 2 calculate column.

And I'll add some details on his basis:

First of all, I create a new table:

Table2 =
SELECTCOLUMNS (
    'Table',
    "outpu_field", LEFT ( 'Table'[Current Input], SEARCH ( ";", 'Table'[Current Input] ) - 1 )
)

vzhengdxumsft_0-1709705517853.png

Then add a new measure:

Output =
VAR _newtable =
    SELECTEDVALUE ( Table2[outpu_field] )
VAR _newoutput =
    SWITCH (
        _newtable,
        "AAAAA", "AAAAA",
        "BBBBBB", "BBBBBB",
        "FFFFFFFF", "FFFFFFFF"
    )
RETURN
    CONCATENATEX (
        ALL ( 'Table' ),
        CALCULATE (
            SELECTEDVALUE ( 'Table'[output_field2] ),
            'Table'[output_field1] = _newoutput
        ),
        " "
    )

The result is as follow:

 

vzhengdxumsft_2-1709705653575.png

Best Regards

Zhengdong Xu
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
Anonymous
Not applicable

Hi @Anupal 

 

@Dangar332 , thanks for your contribution to the forum

Just as he posted that you can add 2 calculate column.

And I'll add some details on his basis:

First of all, I create a new table:

Table2 =
SELECTCOLUMNS (
    'Table',
    "outpu_field", LEFT ( 'Table'[Current Input], SEARCH ( ";", 'Table'[Current Input] ) - 1 )
)

vzhengdxumsft_0-1709705517853.png

Then add a new measure:

Output =
VAR _newtable =
    SELECTEDVALUE ( Table2[outpu_field] )
VAR _newoutput =
    SWITCH (
        _newtable,
        "AAAAA", "AAAAA",
        "BBBBBB", "BBBBBB",
        "FFFFFFFF", "FFFFFFFF"
    )
RETURN
    CONCATENATEX (
        ALL ( 'Table' ),
        CALCULATE (
            SELECTEDVALUE ( 'Table'[output_field2] ),
            'Table'[output_field1] = _newoutput
        ),
        " "
    )

The result is as follow:

 

vzhengdxumsft_2-1709705653575.png

Best Regards

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

Hello @Anonymous  and @Dangar332  many thanks for the responses and the solution provided.

 

It really helped in creating the custom fields.

 

 

Dangar332
Super User
Super User

hi, @Anupal 

 

Add two columns in your current table
try below column code

 

 

outpu_field1=
VAR a = SEARCH(";",'Table (2)'[Current Input Column])
return
LEFT('Table (2)'[Current Input Column],a-1)

 

 

 

 

 

output_field2=
VAR a = SEARCH(";",'Table (2)'[Current Input Column])
var b = LEN('Table (2)'[Current Input Column])
return
RIGHT('Table (2)'[Current Input Column],b-a)

 

 

and it easy in power query

use split column

Dangar332_0-1709619482878.png

 

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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