Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
how 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
Solved! Go to Solution.
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:
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"
)
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsHi @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:
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"
)
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsIts working .
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 57 | |
| 33 | |
| 33 | |
| 18 | |
| 16 |
| User | Count |
|---|---|
| 66 | |
| 64 | |
| 44 | |
| 30 | |
| 29 |