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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
dianate12
Frequent Visitor

calculated column

doubt.PNGhow to achieve this in power bi column,In a table in power bi, I have 3 columns named as "parts" ,"code", "yes/no" are available.Based on parts -->codes are coming , one part will have multiple codes, if a part has "0" in the code then yes should come in the column(Yes/no) for that parts otherwise no sholud come.

 

 

Reference pic has attached 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @dianate12 

 

You can do this in Power Query or DAX.

 

Power Query:

Add a new column with the following code:

 

Table.SelectRows( Table.Group(#"Changed Type", {"Parts"}, {{"MinCode", each List.Min([code]), type nullable number}}) , (x) => x[Parts] = [Parts] )

 

Expand the column and do a replace values with the following expression:

 

= Table.ReplaceValue(#"Changed Type1",each  [#"Yes/No"], each if [#"Yes/No"] = "0" then "Yes" else "No",Replacer.ReplaceText,{"Yes/No"})

 

Result below:

MFelix_0-1684484630563.png

 

Full code:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTJQitWBsIzgLGMwKwkvKxmuAxsrBW5yCooYUG8sAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Parts = _t, code = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Parts", type text}, {"code", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "MinCode", each Table.SelectRows( Table.Group(#"Changed Type", {"Parts"}, {{"MinCode", each List.Min([code]), type nullable number}}) , (x) => x[Parts] = [Parts] )),
    #"Expanded Custom1" = Table.ExpandTableColumn(#"Added Custom", "MinCode", {"MinCode"}, {"Yes/No"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom1",{{"Yes/No", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type1",each  [#"Yes/No"], each if [#"Yes/No"] = "0" then "Yes" else "No",Replacer.ReplaceText,{"Yes/No"})
in
    #"Replaced Value"

 

DAX:

Yes / No DAX =
VAR tt = 'Table'[Parts]
RETURN
    IF (
        MINX (
            FILTER ( ALL ( 'Table'[Parts], 'Table'[code] ), 'Table'[Parts] = tt ),
            'Table'[code]
        ) = 0,
        "Yes",
        "No"
    )

MFelix_1-1684484868311.png

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





View solution in original post

2 REPLIES 2
MFelix
Super User
Super User

Hi @dianate12 

 

You can do this in Power Query or DAX.

 

Power Query:

Add a new column with the following code:

 

Table.SelectRows( Table.Group(#"Changed Type", {"Parts"}, {{"MinCode", each List.Min([code]), type nullable number}}) , (x) => x[Parts] = [Parts] )

 

Expand the column and do a replace values with the following expression:

 

= Table.ReplaceValue(#"Changed Type1",each  [#"Yes/No"], each if [#"Yes/No"] = "0" then "Yes" else "No",Replacer.ReplaceText,{"Yes/No"})

 

Result below:

MFelix_0-1684484630563.png

 

Full code:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTJQitWBsIzgLGMwKwkvKxmuAxsrBW5yCooYUG8sAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Parts = _t, code = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Parts", type text}, {"code", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "MinCode", each Table.SelectRows( Table.Group(#"Changed Type", {"Parts"}, {{"MinCode", each List.Min([code]), type nullable number}}) , (x) => x[Parts] = [Parts] )),
    #"Expanded Custom1" = Table.ExpandTableColumn(#"Added Custom", "MinCode", {"MinCode"}, {"Yes/No"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom1",{{"Yes/No", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type1",each  [#"Yes/No"], each if [#"Yes/No"] = "0" then "Yes" else "No",Replacer.ReplaceText,{"Yes/No"})
in
    #"Replaced Value"

 

DAX:

Yes / No DAX =
VAR tt = 'Table'[Parts]
RETURN
    IF (
        MINX (
            FILTER ( ALL ( 'Table'[Parts], 'Table'[code] ), 'Table'[Parts] = tt ),
            'Table'[code]
        ) = 0,
        "Yes",
        "No"
    )

MFelix_1-1684484868311.png

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Its working .

 

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors