Forum Discussion
Quiz score via Flow?
I'm looking for the same options with Flow & Forms(Quizzes) but unfortunately is seems there is no solution for the moment.
But maybe voting for this ideea: https://powerusers.microsoft.com/t5/Flow-Ideas/Quiz-Reading-quot-Total-Points-quot-Column-from-Response/idi-p/93085 will be in the future...
- SergeiBaklanMay 15, 2019Diamond Contributor
LucianC , yes, unfortunately no direct solution. As workaround I collect answers by flow in Excel file published on SPO. From another Excel Power Query it, as well as table with answers and points in one more file plus some additional information from HR SQL database. This Excel with it's data model is published on Power BI services for scheduled updates. Using it one more flow sends reminders to people who didn't take the test in time and some summary is published in Teams as Power BI report.
Bit complicated, but fully automatic.
- LucianCMay 15, 2019Brass Contributor
SergeiBaklan, thank you for your message and workaround tip. Until Microsoft will decide to shorten my path I think I will have to use your workaround. :-)
The first part with getting the answers into an Excel file is done.
But for the second part - using PowerQuery to match the responses with a "CorrectAnswers" table... is harder for me. Could you point me to a link or an example? I'm a "basic user" with PowerQuery and I don't imagine how could I calculate the total points for each answer.
- SergeiBaklanMay 15, 2019Diamond Contributor
LucianC , let play with such sample
Quiz table is what the flow updates. Answers is the supporting page with points. Final result is in green.
In my case each of above tables is in separate file - answers are separated for the security reason. Source file is separated to avoid any conflicts with flow since that file is practically never opened in opposite to file with results. Most probably it shall be no conflicts even they are in one file, but who know.
First query supporting table and only one transformation is to add the key for Q&A.
let Source = Excel.CurrentWorkbook(){[Name="Points"]}[Content], ProperType = Table.TransformColumnTypes(Source,{ {"Question", type text}, {"Answer", type text}, {"Points", Int64.Type}}), // This is to generate unique key for the combination of Question & Answer AddKey = Table.AddColumn(ProperType, "QAKey", each [Question] & "===" & [Answer]) in AddKey
Query the quiz table, select all columns but questions, unpivot other columns and add the same key for each combination of Q&A. Merge on this key with Points query (into same or separate table) extracting only points. With that GroupBy on all columns except points, aggregate them by sum.
let Source = Excel.CurrentWorkbook(){[Name="Quiz"]}[Content], ProperType = Table.TransformColumnTypes(Source,{ {"Time", type datetime}, {"Name", type text}, {"email", type text}, {"Q1", type text}, {"Q2", type text}, {"Q3", type text}}), UnpivotQuestions = Table.UnpivotOtherColumns(ProperType, {"Time", "Name", "email"}, "Attribute", "Value"), AddKey = Table.AddColumn(UnpivotQuestions, "QAkey", each [Attribute] & "===" & [Value]), MergeWithAnswers = Table.NestedJoin(AddKey, {"QAkey"}, Points, {"QAKey"}, "Points", JoinKind.LeftOuter), GetPoints = Table.ExpandTableColumn(MergeWithAnswers, "Points", {"Points"}, {"Points.1"}), RemoveUnuzed = Table.SelectColumns(GetPoints,{"Time", "Name", "email", "Points.1"}), //Use Advanced option to GroupBy SumPoints = Table.Group(RemoveUnuzed, {"Time", "Name", "email"}, {{"Points", each List.Sum([Points.1]), type number}}) in SumPoints
That's all, the rest is cosmetic.
One more practical point. If you change wording of the question(s) in your form, or even name(s) of the column in Excel table, the flow doesn't care, it will add results correctly based on order of question/columns. Text with answers will be returned by flow as it is. However, both could affect the key as it is generated in this sample. Correction of wording always could happen, even extra space crashes the key.
As variant you may play with texts (trim, lowercase, etc), bt that's not very reliable. Better to work with indexes. For the questions they could be generated internally - sequential numbers in supporting table and pick-up number of columns in quiz query.
With answers is more complex, we can't pick-up any ID for them. Thus we use in Forms numbering list of answers, like
Is England part of EU? a) Yes b) No
with that you extract only first character of each answer, doesn't matter which text will be after that, and work with it.
But that's all improvements and more depends on your concrete data.
You may play with attached file to check how quires work.