Iterating on a set to reduce it
Iteration is a very natural way of thinking for us humans. We set a starting point, we step into a loop, and we end when a condition is met. While we're looping, we can do whatever we want: check, take, leave, and modify items in that set.
In this recipe, we will start from a result set as shown in the following table, and iterate through the days in each fiscal month to count the number of days for which the growth was positive. By to reduce, we mean the filtering effect; in our example, we need to filter out the days for which the growth was not positive. Our goal is still to only display the fiscal months on ROWS, not the days:
Then we will look at a different approach that takes performance advantage of the block- mode calculation.
Getting ready
Start a new query in SSMS against the Adventure Works DW 2016 database. Then write the following query:
SELECT { [Measures].[Customer Count], [Measures].[Growth in Customer Base] } ON 0, ...