Sorting by ForEach()

I am attempting to add a dimension to a calculation using the ForEach() function. However, i need the dimension to be sorted in descending order otherwise the calculation does not work properly. I know that i can use the sort button if i add the dimension to the table, but that is not an option. Any ideas how to sort the dimension in the ForEach() functions. I tried rank and that didnt work.


orangegroves (BOB member since 2010-12-17)

We need more detail than that. For example:

What are you trying to achieve?
Why would the foreach not work if the dimensions are unsorted?


dfoster99 :uk: (BOB member since 2010-11-05)

I am trying to count the number of days in a row that a location has either positive or negative performance starting with today and looking back 7 days. I was able to create the formula that counts the number of days correctly, however this only works while the data is displayed in the table. This variable must then be displayed in a table that has other metric in it, with their titles for what each col. means. so I am unable to display the date. The ForEach() function does add the date to the calculated dimension, but it adds it in the wrong sorted order ( 7 days ago to today instead of today back 7 days) so then the variable calculates based on that, which gives me a wrong answer.

On a side note I tried making a new variable/dimension that ranks business date and then using that in a Foreach() but that didn’t work.


orangegroves (BOB member since 2010-12-17)

I was able to modify my my formula using the relativevalue function to work with the default sorting of the ForEach() function. However if anyone has any tips on how to sort the ForEach() function it would be a very useful piece of knowledge


orangegroves (BOB member since 2010-12-17)