Forum Discussion
Complex Conditional Column
- 4 years ago
Hi,
This calculated column formula works
=if(CALCULATE(COUNTROWS(Table1),FILTER(Table1,Table1[Column A]=EARLIER(Table1[Column A])&&Table1[Column B]="Yes"))>=1,"Yes",BLANK())Hope this helps.
- 4 years ago
See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again).
Note - Replaced value step may not be needed for you as I have used that to generate nulls in place of blank.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rdC7DcAgDATQXVxTYOMfo0SIMhNkfylARYRCmrRPZ53tUgApimZjVjEIcJwX1LDw1gyZWXL+1TTxh6lTn7X0YtMpm6jTZIatotX4wzz2nC6mcX6DMY0VcVi9AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Column A" = _t, #"Column B" = _t]), #"Replaced Value" = Table.ReplaceValue(Source,"",null,Replacer.ReplaceValue,{"Column B"}), #"Changed Type" = Table.TransformColumnTypes(#"Replaced Value",{{"Column A", Int64.Type}, {"Column B", type text}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Column A"}, {{"Temp", each _, type table [Column A=nullable number, Column B=nullable text]}}), //Function Start fxProcess=(Tbl)=> let #"Added Custom" = Table.AddColumn(Tbl, "Column C", each if List.Count(List.Select(Tbl[Column B],each _="Yes"))>0 then "Yes" else null) in #"Added Custom", //Function End #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each fxProcess([Temp])), #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Column B", "Column C"}, {"Column B", "Column C"}), #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Temp"}) in #"Removed Columns"
Hi Anonymous
Try this code to add a new column with DAX:
Column C =
VAR _Yes =
CALCULATE (
COUNTROWS ( 'Table' ),
FILTER ( ALLEXCEPT ( 'Table', 'Table'[Column A] ), 'Table'[Column B] = "Yes" )
)
RETURN
IF ( _Yes > 0, "Yes", BLANK () )
Output:
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: www.linkedin.com/in/vahid-dm/
This is great - thank you! I appreciate the help.
Like Ashish's solution, this solution totally works in DAX. However, I need to do this in Power Query because I subsequently merge this table with another. Any suggestions for that?