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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
cnwonge
Regular Visitor

create a new column with distinct value from two column combination

Dear brother,

 

I am newbie in DAX, and would like to have Dax code to achieve,Capture.PNG

 

 

Data table is simplifed, it consists of hundred thousand record,

 

Would like to define them as the catagory logic into five options depends the "WBS" (A or B) and "Value"(1 or 0) combinaton.

 

Many thanks 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @cnwonge,

 

I think you need to add a group column for each A,B group.

 

Sample steps:

3.PNG


Then you can reference above table to transpose table and group records.

4.PNG

 

Full query:

 

let
    Source  = Records,
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", type text}, {"WBS", type text}, {"value", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Item", "Group ID"}, {{"Records", each Table.PromoteHeaders(Table.Transpose(Table.SelectColumns(_,{"WBS","value"})), [PromoteAllScalars=true]), type table}}),
    #"Expanded Records" = Table.ExpandTableColumn(#"Grouped Rows", "Records", {"A", "B"}, {"A", "B"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Records",{{"Item", type text}, {"Group ID", Int64.Type}, {"A", Int64.Type}, {"B", Int64.Type}})
in
    #"Changed Type1"

 

 

Salve changes and exit query editor.

 

Write a measure to check records between transpose table and category table.

 

Category tag = 
VAR _currentitem =
    SELECTEDVALUE ( 'Records Transpose'[Item] )
VAR seleceted =
    SELECTCOLUMNS (
        FILTER ( ALL ( 'Records Transpose' ), [Item] = _currentitem ),
        "A", [A],
        "B", [B]
    )
RETURN
    CONCATENATEX (
        FILTER (
            ALL ( Category ),
            CONTAINS ( seleceted, [A], Category[A], [B], Category[B] )
        ),
        [Category],
        ","
    )

5.PNG

 

Notice: I attach sample file below.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

Hi @cnwonge,

 

I think you need to add a group column for each A,B group.

 

Sample steps:

3.PNG


Then you can reference above table to transpose table and group records.

4.PNG

 

Full query:

 

let
    Source  = Records,
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", type text}, {"WBS", type text}, {"value", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Item", "Group ID"}, {{"Records", each Table.PromoteHeaders(Table.Transpose(Table.SelectColumns(_,{"WBS","value"})), [PromoteAllScalars=true]), type table}}),
    #"Expanded Records" = Table.ExpandTableColumn(#"Grouped Rows", "Records", {"A", "B"}, {"A", "B"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Records",{{"Item", type text}, {"Group ID", Int64.Type}, {"A", Int64.Type}, {"B", Int64.Type}})
in
    #"Changed Type1"

 

 

Salve changes and exit query editor.

 

Write a measure to check records between transpose table and category table.

 

Category tag = 
VAR _currentitem =
    SELECTEDVALUE ( 'Records Transpose'[Item] )
VAR seleceted =
    SELECTCOLUMNS (
        FILTER ( ALL ( 'Records Transpose' ), [Item] = _currentitem ),
        "A", [A],
        "B", [B]
    )
RETURN
    CONCATENATEX (
        FILTER (
            ALL ( Category ),
            CONTAINS ( seleceted, [A], Category[A], [B], Category[B] )
        ),
        [Category],
        ","
    )

5.PNG

 

Notice: I attach sample file below.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.