How to display rows that have more than two Column Row values in common with Power Bi Dax?
Question:
I have table called ‘Marks’, there are columns named ‘ChildId’,’Test1′, ‘Test2’, ‘Test3’ and onwards.
My goal is to make a new column only identifying if the child Failed or Passed the semester. where a child will fail a semester if he/she failed more than 2 tests.
For example if the the child nr.5 failed only Test 1 but pass the rest then that new column value will show pass. But where child nr.6 failed Test 1, test 2 and test 3 so his new column value at the end will show Failed.
Here is my idea in python pseudo, I would like to convert this to Power Bi Dax but not sure how that would look. Any help would be appreciated.
var = count(test1==Failed or test2==Failed or .... testn==Failed)
if var >= 2:
markval = Failed
else:
markval= Pass
Answers:
Boolean values like Marks[Test1] = "Failed"
are evaluated to 0/1, so you could use simple sum, e.g.
Column = IF(
(Marks[Test1] = "Failed") + (Marks[Test2] = "Failed") + (Marks[Test3] = "Failed") >= 2,
"Failed",
"Passed"
)
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJLzMxJTQEyAhKLizEoVNlYnWglI2RRYhhwncZYbCOoLxYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ChildID = _t, Test1 = _t, Test2 = _t, Test3 = _t, Test4 = _t, Test5 = _t, Test6 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ChildID", Int64.Type}, {"Test1", type text}, {"Test2", type text}, {"Test3", type text}, {"Test4", type text}, {"Test5", type text}, {"Test6", type text}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ChildID"}, "Attribute", "Value"),
#"Grouped Rows" = Table.Group(#"Unpivoted Other Columns", {"ChildID", "Value"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
#"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each [Count] >= 2 and [Value] = "Pass")
in
#"Filtered Rows"
You can also check this calculated column: If some students fails more than 2 tests, and there is 3 tests, then only combination leading to "failed state" is ‘Fail-Fail-Fail’. Employing this concept, we can write this DAX Code:
Let’s say we have a table like this:
Judgement =
IF (
[Test1] & "-" & [Test2] & "-" & [Test3] = "Fail-Fail-Fail",
"Fail",
"Pass"
)
Then if we test our code, result It produces:
I have table called ‘Marks’, there are columns named ‘ChildId’,’Test1′, ‘Test2’, ‘Test3’ and onwards.
My goal is to make a new column only identifying if the child Failed or Passed the semester. where a child will fail a semester if he/she failed more than 2 tests.
For example if the the child nr.5 failed only Test 1 but pass the rest then that new column value will show pass. But where child nr.6 failed Test 1, test 2 and test 3 so his new column value at the end will show Failed.
Here is my idea in python pseudo, I would like to convert this to Power Bi Dax but not sure how that would look. Any help would be appreciated.
var = count(test1==Failed or test2==Failed or .... testn==Failed)
if var >= 2:
markval = Failed
else:
markval= Pass
Boolean values like Marks[Test1] = "Failed"
are evaluated to 0/1, so you could use simple sum, e.g.
Column = IF(
(Marks[Test1] = "Failed") + (Marks[Test2] = "Failed") + (Marks[Test3] = "Failed") >= 2,
"Failed",
"Passed"
)
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJLzMxJTQEyAhKLizEoVNlYnWglI2RRYhhwncZYbCOoLxYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ChildID = _t, Test1 = _t, Test2 = _t, Test3 = _t, Test4 = _t, Test5 = _t, Test6 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ChildID", Int64.Type}, {"Test1", type text}, {"Test2", type text}, {"Test3", type text}, {"Test4", type text}, {"Test5", type text}, {"Test6", type text}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ChildID"}, "Attribute", "Value"),
#"Grouped Rows" = Table.Group(#"Unpivoted Other Columns", {"ChildID", "Value"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
#"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each [Count] >= 2 and [Value] = "Pass")
in
#"Filtered Rows"
You can also check this calculated column: If some students fails more than 2 tests, and there is 3 tests, then only combination leading to "failed state" is ‘Fail-Fail-Fail’. Employing this concept, we can write this DAX Code:
Let’s say we have a table like this:
Judgement =
IF (
[Test1] & "-" & [Test2] & "-" & [Test3] = "Fail-Fail-Fail",
"Fail",
"Pass"
)
Then if we test our code, result It produces: