Forum Discussion

jakaihammuda's avatar
jakaihammuda
Helper III
2 years ago
Solved

Creating logic for a Correct or Incorrect Flag in table

Hello,   Im looking for some help in creating a flag which determines whether a question has been asnwered correctly or incorrectly.   The issues im facing is that i dont know how to make the log...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi jakaihammuda ,

    Since you can be sure that all questions are objective, we can use a very simple way to complete this question. I recreated the test data set:

     

    I assume that the questions are single choice, unordered multiple choice, judgment, sorting on two items and sorting on three items.
    Then as before, New Source -> Blank Query:

    And put all of the M function into the Advanced Editor:

     

     

    let
        Source = Table.NestedJoin(FACT, {"QuestionID"}, DIM, {"QuestionID"}, "DIM", JoinKind.FullOuter),
        #"Expanded DIM" = Table.ExpandTableColumn(Source, "DIM", {"CorrectAnswers", "IsOrder"}, {"CorrectAnswers", "IsOrder"}),
        #"Added Custom" = Table.AddColumn(#"Expanded DIM", "Custom", each if [IsOrder] = 0 then 
       if [Answer] = [CorrectAnswers] then "Right"
       else if Text.Contains([CorrectAnswers], [Answer]) and not Text.Contains([Answer], [CorrectAnswers]) then "Lack of other answer"
       else "Wrong"
    else
       if [Answer] = [CorrectAnswers] then "Right"
       else if Text.Length([Answer]) = Text.Length([CorrectAnswers]) then "Wrong order"
       else "Lack of other answer"),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"IsOrder", "CorrectAnswers"}),
        #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"UserID", "Answer", "Custom", "QuestionID"})
    in
        #"Reordered Columns"

     

     

    The final output is as below:


    Best Regards,
    Dino Tao
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.