378 Practical PowerPivot & DAX Formulas for Excel 2010
3.
Click in cell A10. Enter the following formula:
=CUBESET("PowerPivot Data","[Products].[Category].[All].Children",
"Category")
is is using MDX to create the children of the All member of Category (for
example, Beverages). e third parameter is a caption. Further parameters, not
shown here, allow you to specify a sort order and a measure to sort on. For a
full discussion of the CUBE() functions, you are referred to Excel Help. To
understand the CUBE() functions, it helps to have a little knowledge of MDX.
4. Click in cell A11 and enter the following formula:
=IFERROR(CUBERANKEDMEMBER("PowerPivot Data",$A$10,ROW(A1)),"")
is formula is going to retrieve the first product category, Beverages, from the set
defined in cell A10. ROW(A1) returns 1, but you can’t use 1, as this cell is going to
be copied down and we want it to return the second category, then the third, and
so on. Hard-coded numerals are, well, hard-coded. e IFERROR() function is to
suppress nonexistent categories, if we copy too far down.
5. Copy cell A11 from A12 to about A20. You should see a total of eight categories
(including Beverages). You may want to widen column A, to display the complete
names of the categories.
6. Click in cell B11 and enter this formula:
=IFERROR(CUBEVALUE("PowerPivot Data",$A11,$B$9,$C$9),"")
is function is referencing Beverages (A11) and the report filter on Year (B9)
and the Sales measure (C9). In other words, it’s returning the Sales for Beverages
for the current filter on Year. You may have to widen the column for the number
to display in non-scientific format.
7. Copy B11 from B12 to about B20. Hopefully, you can see the sales for each
category. Experiment with the Year filter. My result is shown in Figure 12-32.
8. Instead of a Report Filter on Year, you may prefer to use the Year slicer. It’s also
probably overkill to have Year in both a Report Filter and a slicer, as here. If you
do reference the slicer, the formula for B11 might look like this:
=IFERROR(CUBEVALUE("PowerPivot Data",$A11,Slicer_Year,$C$9),"")
Please note the third parameter of CUBEVALUE() now references the slicer. To
verify the name of a slicer, open the Slicer Settings dialog and check the Name
to use in formulas entry. e slicer name is not enclosed in quotes. In addition,
this example formula assumes that Excel column and row references are still
valid. If you want to use a slicer, it’s probably a good idea to add the slicer before