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") ' Select only brand tagged questions for use in rows Dim questionForSortOrder = ^B1^ ' Set the question whose sort order you want to reuse across all brand questions Dim arrCounts = {} Dim arrSortedIndexes = {} Dim i For i = 1 to questionForSortOrder.Responses.Count-1 arrCounts.Push(questionForSortOrder.Data.Counts({}.Merge(i))[1]) ' Push the counts from your question for sort order into an array Next i Dim k For k = 1 to questionForSortOrder.Responses.Count-1 arrSortedIndexes.Push(arrCounts.IndexOfMax(k)) ' push into an array of sorted indexes 1st highest to nth higest counts from arrCounts Next k ' 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 ' Prepare to iterate through every question of the survey Dim currQuestion = Survey.Questions[h] 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 - Maintaining Sort Order from B1: " + arrSortedIndexes.ToString()) 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()