Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hi.
I want to create a Custom Column in Power Query where if column is null and the other column contains information (any data) it says FALSE.
And another condition if both columns have data it says YES.
In this particular case I don't want to specify the amount on the cell that contains data.
See below:
ID | DEBIT | CREDIT | EXPECTED RETURN |
1001 | null | 1 | FALSE |
1002 | 2 | null | FALSE |
1003 | null | 2 | FALSE |
1004 | null | 2 | FALSE |
1005 | 1 | 2 | TRUE |
1006 | 2 | 1 | TRUE |
Solved! Go to Solution.
Hi @Anonymous ,
You could try below M code to see whether it work or not.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFTSUcorzckBUoZKsTpgMSMgxwgmDhUzRqgzgomZYBEzBRuEJGAGNQxoeiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, DEBIT = _t, CREDIT = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"DEBIT", Int64.Type}, {"CREDIT", Int64.Type}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ID"}, "Attribute", "Value"),
#"Grouped Rows" = Table.Group(#"Unpivoted Columns", {"ID"}, {{"Count", each Table.RowCount(_), type number}, {"all", each _, type table [ID=number, Attribute=text, Value=number]}}),
Custom1 = Table.ReplaceValue( #"Grouped Rows",each [Count], each if [Count]>1 then "True" else "False", Replacer.ReplaceValue, {"Count"}),
#"Expanded all" = Table.ExpandTableColumn(Custom1, "all", {"Attribute", "Value"}, {"Attribute", "Value"}),
#"Pivoted Column" = Table.Pivot(#"Expanded all", List.Distinct(#"Expanded all"[Attribute]), "Attribute", "Value", List.Sum)
in
#"Pivoted Column"
Best Regards,
Zoe Zhi
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
if [DEBIT] = null OR [CREDIT] = null then false else true
?
Hi Greg! Thanks for your response.
But in my scenario I won't have nulls values in the same row for both columns.
I want to put a condition that if COLUMN A contains data and COLUMN B contains data then TRUE. Else would be false because on either columns a null value is displayed.
Hope that is clear! but thanks anyway 🙂
Hi @Anonymous ,
You could try below M code to see whether it work or not.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFTSUcorzckBUoZKsTpgMSMgxwgmDhUzRqgzgomZYBEzBRuEJGAGNQxoeiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, DEBIT = _t, CREDIT = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"DEBIT", Int64.Type}, {"CREDIT", Int64.Type}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ID"}, "Attribute", "Value"),
#"Grouped Rows" = Table.Group(#"Unpivoted Columns", {"ID"}, {{"Count", each Table.RowCount(_), type number}, {"all", each _, type table [ID=number, Attribute=text, Value=number]}}),
Custom1 = Table.ReplaceValue( #"Grouped Rows",each [Count], each if [Count]>1 then "True" else "False", Replacer.ReplaceValue, {"Count"}),
#"Expanded all" = Table.ExpandTableColumn(Custom1, "all", {"Attribute", "Value"}, {"Attribute", "Value"}),
#"Pivoted Column" = Table.Pivot(#"Expanded all", List.Distinct(#"Expanded all"[Attribute]), "Attribute", "Value", List.Sum)
in
#"Pivoted Column"
Best Regards,
Zoe Zhi
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.