Forum Discussion
InsightSeeker
Helper III
2 years agoNeed help with DAX
I need help to achieve the results shown in the table below.
Essentially, in the 'Category' column, if all the values are the same, then return the first value; otherwise, return 'Mix'.
Table
| Category |
| Apple-Apple |
| Apple-Grapes |
| Apple |
| Grapes-Grapes |
| Grapes-Apple-Apple-Grapes |
Grapes |
Result
| Category | Result |
| Apple-Apple | Apple |
| Apple-Grapes | Mix |
| Apple | Apple |
| Grapes-Grapes | Grapes |
| Grapes-Apple-Apple-Grapes | Mix |
| Grapes | Grapes |
InsightSeeker , Add new custom column in Power Query
let
_list = List.Distinct( Text.Split([Category],"-")),
_res= if List.Count(_list)=1 then List.Max(_list) else "Mix"
in
_resFull Code - Paste in Blank query in Power query
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WciwoyEnVBZNKsTowvntRYkFqMUIAzIIIIstBRZDMwJRVio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let _list = List.Distinct( Text.Split([Category],"-")), _res= if List.Count(_list)=1 then List.Max(_list) else "Mix" in _res) in #"Added Custom"
1 Reply
- amitchandak
Super User
InsightSeeker , Add new custom column in Power Query
let
_list = List.Distinct( Text.Split([Category],"-")),
_res= if List.Count(_list)=1 then List.Max(_list) else "Mix"
in
_resFull Code - Paste in Blank query in Power query
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WciwoyEnVBZNKsTowvntRYkFqMUIAzIIIIstBRZDMwJRVio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let _list = List.Distinct( Text.Split([Category],"-")), _res= if List.Count(_list)=1 then List.Max(_list) else "Mix" in _res) in #"Added Custom"