{"id":1484,"date":"2015-11-25T12:57:29","date_gmt":"2015-11-25T12:57:29","guid":{"rendered":"http:\/\/turtlellc.com\/?p=1484"},"modified":"2017-09-22T19:56:00","modified_gmt":"2017-09-22T19:56:00","slug":"dynamic-excel-cubevalue-and-cubemember-functions","status":"publish","type":"post","link":"https:\/\/www.turtle.works\/knowledge\/dynamic-excel-cubevalue-and-cubemember-functions\/","title":{"rendered":"Dynamic Excel CUBEVALUE and CUBEMEMBER Functions"},"content":{"rendered":"<p>We recently ran into a situation where a client needed to change the filter in an Excel report that is using the CUBEVALUE and CUBEMEMBER functions. The report was built using a pivot table going against a cube. We then used Convert to Formulas so we could control the report format. This approach worked great for the current data, but lacked a simple way to update the report every month by selecting a new period from a drop down. After some struggles and some seemingly dead ends, we had enough information to solve the problem.<!--more--><\/p>\n<h3>Problem<\/h3>\n<p>The CUBEMEMBER function used an array of values for retrieving data:<\/p>\n<p style=\"padding-left: 30px;\">=CUBEMEMBER(&#8220;AW BI Cube&#8221;,<strong>{&#8220;[Date].[Calendar Weeks].[Calendar Year].&amp;[2014]&#8221;,&#8221;[Account].[Accounts].&amp;[47]&#8221;}<\/strong>)<\/p>\n<p>The bolded segment above is the array. We know it&#8217;s an array because of the braces {} surrounding the values. The array has 2 values:<\/p>\n<ol>\n<li>[Date].[Calendar Weeks].[Calendar Year].&amp;[2014]<\/li>\n<li>[Account].[Accounts].&amp;[47]<\/li>\n<\/ol>\n<p>Because it&#8217;s\u00a0an array we can&#8217;t simply replace &amp;[2014] with\u00a0&amp;A1. Where A1 = [2015]. Excel won&#8217;t accept cell references within an array.<\/p>\n<h3>Solution<\/h3>\n<p>If we read the CUBEMEMBER <a title=\"CUBEMEMBER function\" href=\"https:\/\/support.office.com\/en-us\/article\/CUBEMEMBER-function-0f6a15b9-2c18-4819-ae89-e1b5c8b398ad\" target=\"_blank\" rel=\"noopener\">documentation<\/a><\/p>\n<figure id=\"attachment_1487\" aria-describedby=\"caption-attachment-1487\" style=\"width: 665px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/CUBEMEMBER_Doc.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1487 \" title=\"CUBEMEMBER Documentation\" src=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/CUBEMEMBER_Doc.png\" alt=\"https:\/\/support.office.com\/en-us\/article\/CUBEMEMBER-function-0f6a15b9-2c18-4819-ae89-e1b5c8b398ad\" width=\"665\" height=\"180\" \/><\/a><figcaption id=\"caption-attachment-1487\" class=\"wp-caption-text\">CUBEMEMBER Documentation<\/figcaption><\/figure>\n<p>we discover that a cell range can be used instead of an array constant. Now we just need to:<\/p>\n<ol>\n<li>Convert the 2 member array to a cell range with 2 cells<\/li>\n<li>Swap out cell references for the hardcoded values<\/li>\n<li>Clean up the report<\/li>\n<\/ol>\n<h3>Exercise<\/h3>\n<p>Using AdventureWorks I&#8217;ve constructed a report by creating a Pivot Table and then Converting to Formulas<\/p>\n<p><span style=\"color: #333333;\">If we look at the formula in B5, we see the hardcoded year.<\/span><\/p>\n<figure id=\"attachment_1502\" aria-describedby=\"caption-attachment-1502\" style=\"width: 610px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/After-Convert-to-Formulas1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1502 \" src=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/After-Convert-to-Formulas1.png\" alt=\"After Convert to Formulas\" width=\"610\" height=\"140\" \/><\/a><figcaption id=\"caption-attachment-1502\" class=\"wp-caption-text\">After Convert to Formulas<\/figcaption><\/figure>\n<ol>\n<li>Let&#8217;s add 6 rows at the top to work in<\/li>\n<li>In A2 enter the value [2014]<br \/>\n<figure id=\"attachment_1500\" aria-describedby=\"caption-attachment-1500\" style=\"width: 391px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/Added-2014.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1500 \" src=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/Added-2014-e1448403692274.png\" alt=\"Added [2014]\" width=\"391\" height=\"361\" \/><\/a><figcaption id=\"caption-attachment-1500\" class=\"wp-caption-text\">Added [2014]<\/figcaption><\/figure><\/li>\n<li>Copy the array in to Notepad\n<p><figure id=\"attachment_1503\" aria-describedby=\"caption-attachment-1503\" style=\"width: 600px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/Array11.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-1503 \" src=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/Array11.png\" alt=\"Array1\" width=\"600\" height=\"75\" \/><\/a><figcaption id=\"caption-attachment-1503\" class=\"wp-caption-text\">Array1<\/figcaption><\/figure><\/li>\n<li>Break it down to 2 elements<br \/>\n<a style=\"text-align: center; background-color: #f3f3f3;\" href=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/Array2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1494\" src=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/Array2.png\" alt=\"Array2\" width=\"413\" height=\"61\" \/><br \/>\n<\/a><\/li>\n<li>Put the elements into B2 and B3<\/li>\n<li>\u00a0Change the formula in B2 ( [2014]) to use a Cell Range with absolute position ($)\n<p><figure id=\"attachment_1508\" aria-describedby=\"caption-attachment-1508\" style=\"width: 595px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/Range-w-Cell-Ref1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1508 \" src=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/Range-w-Cell-Ref1.png\" alt=\"Range w Cell Ref\" width=\"595\" height=\"147\" \/><\/a><figcaption id=\"caption-attachment-1508\" class=\"wp-caption-text\">Range w Cell Ref<\/figcaption><\/figure><\/li>\n<li>Change the formula in B11 to use a Cell Range\n<p><figure id=\"attachment_1513\" aria-describedby=\"caption-attachment-1513\" style=\"width: 600px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/B11-After-Range3.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-1513 \" src=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/B11-After-Range3.png\" alt=\"B11 After Range\" width=\"600\" height=\"300\" \/><\/a><figcaption id=\"caption-attachment-1513\" class=\"wp-caption-text\">B11 After Range<\/figcaption><\/figure><\/li>\n<li>\u00a0Duplicate the Cell Range in B2 and B3 for C thru H by highlighting the 2 cells and dragging the corner over to column H<\/li>\n<li>Update the Account number to match what is in row 11 for each column\n<p><figure id=\"attachment_1516\" aria-describedby=\"caption-attachment-1516\" style=\"width: 600px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/Account-Number3.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-1516 \" src=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/Account-Number3.png\" alt=\"Account Number\" width=\"600\" height=\"224\" \/><\/a><figcaption id=\"caption-attachment-1516\" class=\"wp-caption-text\">Account Number<\/figcaption><\/figure><\/li>\n<li>Duplicate the formula in B11 by dragging the corner all the way to column H. This changes each formula to use the Cell Ranges in rows 2 and 3 your column headers should update but have the same values.\n<p><figure id=\"attachment_1517\" aria-describedby=\"caption-attachment-1517\" style=\"width: 600px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/Column-Header-Formulas.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-1517 \" src=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/Column-Header-Formulas.png\" alt=\"Column Header Formulas\" width=\"600\" height=\"253\" \/><\/a><figcaption id=\"caption-attachment-1517\" class=\"wp-caption-text\">Column Header Formulas<\/figcaption><\/figure><\/li>\n<li>Change B10s formula for Column Labels to use a Cell Ref\n<p><figure id=\"attachment_1518\" aria-describedby=\"caption-attachment-1518\" style=\"width: 600px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/Column-Label.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-1518 \" src=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/Column-Label.png\" alt=\"Column Label\" width=\"600\" height=\"275\" \/><\/a><figcaption id=\"caption-attachment-1518\" class=\"wp-caption-text\">Column Label<\/figcaption><\/figure><\/li>\n<li>Test it by changing A2 from [2014] to [2013]\n<p><figure id=\"attachment_1519\" aria-describedby=\"caption-attachment-1519\" style=\"width: 600px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/Test-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-1519 \" src=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/Test-1.png\" alt=\"Test 1\" width=\"600\" height=\"275\" \/><\/a><figcaption id=\"caption-attachment-1519\" class=\"wp-caption-text\">Test 1<\/figcaption><\/figure><\/li>\n<li>Cleanup\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>Add a drop down list at A5 for year<\/li>\n<li>Change A2 to a Cell Ref pointing to A5<\/li>\n<li>Hide rows 1 thru 3<\/li>\n<li>Below is the completed report<a style=\"text-align: center; background-color: #f3f3f3;\" href=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/Finished-Report.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-1520 \" src=\"http:\/\/turtlellc.com\/wp-content\/uploads\/2015\/11\/Finished-Report.png\" alt=\"Finished Report\" width=\"540\" height=\"308\" \/><\/a><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>Finished Report<\/li>\n<\/ol>\n<p>So there you have it. A dynamic report using CUBEMEMBER even though it contained arrays. The method is the same for CUBEVALUE.<\/p>\n<p>I want to thank <a href=\"http:\/\/metricx.com\/about-metric-x\/leadership-team\/\" target=\"_blank\" rel=\"noopener\">Saad Shah<\/a> for partnering on this solution.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We recently ran into a situation where a client needed to change the filter in an Excel report that is using the CUBEVALUE and CUBEMEMBER functions. The report was built using a pivot table going against a cube. We then used Convert to Formulas so we could control the report format. This approach worked great &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.turtle.works\/knowledge\/dynamic-excel-cubevalue-and-cubemember-functions\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Dynamic Excel CUBEVALUE and CUBEMEMBER Functions&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":1529,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,10],"tags":[],"class_list":["post-1484","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-business-intelligence","category-excel"],"_links":{"self":[{"href":"https:\/\/www.turtle.works\/knowledge\/wp-json\/wp\/v2\/posts\/1484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.turtle.works\/knowledge\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.turtle.works\/knowledge\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.turtle.works\/knowledge\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.turtle.works\/knowledge\/wp-json\/wp\/v2\/comments?post=1484"}],"version-history":[{"count":1,"href":"https:\/\/www.turtle.works\/knowledge\/wp-json\/wp\/v2\/posts\/1484\/revisions"}],"predecessor-version":[{"id":1703,"href":"https:\/\/www.turtle.works\/knowledge\/wp-json\/wp\/v2\/posts\/1484\/revisions\/1703"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.turtle.works\/knowledge\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/www.turtle.works\/knowledge\/wp-json\/wp\/v2\/media?parent=1484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.turtle.works\/knowledge\/wp-json\/wp\/v2\/categories?post=1484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.turtle.works\/knowledge\/wp-json\/wp\/v2\/tags?post=1484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}