Dim resPortfolio As Portfolio Dim ProfileRow as Profile ' Define a profile of row questions to add to Dim ProfileCol as Profile ' Define a profile of column questions to add to ' Define the array of questions tagged as 'BrandList' Dim arrRowQuestions = Survey.Questions.FilterByTag("BrandList") ' Set the wave response numbers for previous & current waves Dim numPrevWave = ^Wave^.Responses.Count-2 Dim numCurrWave = ^Wave^.Responses.Count-1 Dim resItem As PortfolioItem Dim h For h = 1 to Survey.Questions.Count ' iterate through every question of the survey Dim currQuestion = Survey.Questions[h] Dim arrCounts = {} Dim arrSortedIndexes = {} Dim i For i = 1 to currQuestion.Responses.Count ' iterate through every response of every question in the survey arrCounts.Push(currQuestion.Data.Counts({}.Push(i))[1]) ' push the counts of each response into an array Next i ' Move on to the next response Dim q For q = 1 to 5 arrSortedIndexes.Push(arrCounts.IndexOfMax(q)) ' push into an array of sorted indexes (based on 1st highest to 5th higest counts from arrCounts) Next q If arrRowQuestions.FindByShortcut(currQuestion.Shortcut).Shortcut <> "" and currQuestion.IsCoding = False Then ' Only for (non-grouped/coding) BrandList q's ProfileRow.Add(currQuestion,arrSortedIndexes) ' Add the matched question to the row question profile Endif Next h ' Move on to the next question Dim arrWaveCurrPrev = {}.Push(numPrevWave).Push(numCurrWave) ' set the indexes for the wave variable to show previous vs current wave only ProfileCol.Add(^Wave^,arrWaveCurrPrev) ' add this this to the column profile resItem.SetType(1) resItem.SetTitle("Brand Lists Portfolio - Keep Top 5") resItem.TabDef.ReadTabTemplate("Askia2.1") resItem.TabDef.Title = "??R?? x ??C??" resItem.TabDef.SetUniverse(-3) resItem.TabDef.ReadTabStyle("Black forest") resItem.TabDef.Rows.add(ProfileRow) ' Add the row question profile to the tab definition resItem.TabDef.Columns.add(ProfileCol) resPortfolio.Add(resItem) ' Add the tab definition to the portfolio resPortfolio.Save(Survey.Directory + "Sort Order Maintained.xml") resPortfolio.Open()