2

I have the following expression in Excel that works fine.

=CUBESET("ThisWorkbookDataModel",
"TopCount(
[ProductBV].[Product Name].Children,10, 
sum(
(
[Calendar].[Week Ending].[All].[1/6/2013]:[Calendar].[Week Ending].[All].["&TEXT($E$2,"m/d/yyyy")&"],
[ProductBV].[Moderation Status (ALL)].[All].["&$E$3&"]
),
[Measures].[Product Review Count]
)
)",
"Top 10 to date")

The Product Review Count measure using the following DAX formula.

Product Review Count:=COUNTROWS(ProductBV)

However, when I change the DAX measure to one that utilizes an AVERAGE function (Product Avg Review), the CUBESET function does not work correctly. It still has the correct number of items in the CUBESET, but when I use CUBERANKEDMEMBER(1-10), it does not show me the top 10 Products by Average Rating.

Product Avg Review:=AVERAGE(ProductBV[Rating])

'Not working correctly' expression below:

 =CUBESET("ThisWorkbookDataModel",
"TopCount(
[ProductBV].[Product Name].Children,10, 
sum(
(
[Calendar].[Week Ending].[All].[1/6/2013]:[Calendar].[Week Ending].[All].["&TEXT($E$2,"m/d/yyyy")&"],
[ProductBV].[Moderation Status (ALL)].[All].["&$E$3&"]
),
[Measures].[Product Avg Review]
)
)",
"Top 10 to date")

All in all, my data is very simple. I have one data table connected to a calendar table that contains my product name, rating, date and review status.

The within my dashboard, my date ($E$2) and the review status ($E$3) can be changed by the user via a dropdown.

+-----------------+-------------------+------------+----------------+
| Submission Date | Moderation Status | Product ID | Overall Rating |
+-----------------+-------------------+------------+----------------+
| 10/23/2016      | APPROVED          | Product 1  |              5 |
| 10/23/2016      | APPROVED          | Product 2  |              5 |
| 10/23/2016      | APPROVED          | Product 3  |              5 |
| 10/23/2016      | REJECTED          | Product 3  |              3 |
| 10/23/2016      | REJECTED          | Product 4  |              3 |
+-----------------+-------------------+------------+----------------+

Can anyone tell me why this is happening and how to fix it?

Chris
  • 737
  • 3
  • 16
  • 32
  • I am curious about the need for using Excel functions. Why don't you just calculate that using DAX in your PowerPivot model?. If you provide details about your model we could give you some advice. – alejandro zuleta Nov 18 '16 at 22:27
  • My reason for using Excel's function was to display on a dashboard the top 10 Products by the amount their average rating has changed week over week. Because i have hundreds of products I only want the top 10 to display rather than a large table which is sorted by the amount the rating has changed. Happy to do it all in DAX (and provide model details), but am unsure how this approach would my result without using Excel functions. – Chris Nov 22 '16 at 16:17
  • In DAX you can easily get the average for the top 10 products in a specific date range. As mentioned previously if you provide model and sample data we could give you some advice. – alejandro zuleta Nov 22 '16 at 16:20
  • Woah - great to know. What method would be best to send you this model? Would need an hour to create dummy data as it's client sensitive. Thanks! – Chris Nov 22 '16 at 16:24
  • Just edit your question to include those details. Check [this](http://meta.stackexchange.com/questions/96125/how-to-format-sql-tables-in-a-stack-overflow-post) post. Also you can provide a link to download an excel file from any cloud storage service, drive, dropbox etc. – alejandro zuleta Nov 22 '16 at 16:28
  • Will follow the instructions and thanks again for your help. This problem as been bugging me for months. If you post your comment as an answer, I'm happy to award you the bounty points as they're ending in 3 hours :) – Chris Nov 22 '16 at 16:33
  • Cool - I've redacted the data and uploaded the file here - https://www.dropbox.com/s/3ktkx8yubtlh94z/Top%2010%20Movers%20v2.xlsx?dl=0 – Chris Nov 22 '16 at 17:24
  • What are you trying to calculate in the Movement column? If I understand your requeriment you need the Top 5 products with the highest product avg review to the date, do you mean the selected weeking ending date (in your example 11/09/2016) or the current date (22/11/2016)? – alejandro zuleta Nov 23 '16 at 01:58
  • The movement would be a calculation showing: the average rating from my first recorded date (3/21/13) to whatever date was selected in the dropdown, MINUS the average rating from my first recorded date (3/21/13) to the WEEK PRIOR whatever date was selected in the dropdown. The business requirement is to monitor online ratings of the differing products and see what products have changed the most WoW. User input from the dropdown to change the week is also a requirment - not just current date. – Chris Nov 23 '16 at 13:18

2 Answers2

2

This produces a set CUBESET.

A set has a count so I can appreciate that COUNTROWS will function correctly.

If you feed a set of members into AVERAGE which measure does it average over? This seems to be non-determinant ?

Can you feed the set returned by ProductBV[Rating] into a subsequent cube function that specifies the measure you'd like to have the average of?

whytheq
  • 34,466
  • 65
  • 172
  • 267
  • Thanks for the reply. For your first two comments, you are correct in saying that this my formula returns a CUBESET and COUNTROWS is working correctly. I don't quite understand what you mean in your third comment (still very new to MDX). [Product Avg Review] is the average of my [Product Rating] for my [Product Name]. For your last comment, are you suggesting to nest my sets so that the outer does the topcount and the inner pulls my Product Avg Review filtered by the date range and Moderation status? I've made some minor edits to my post if that helps – Chris Oct 29 '16 at 17:16
  • @Chris ok - my mistake - so `AVERAGE(ProductBV[Rating])` is DAX? – whytheq Oct 29 '16 at 17:20
  • That's right. Cube functions in Excel accessing a PowerPivot data model. Sorry - should have been explicit in my initial post – Chris Oct 29 '16 at 18:32
  • Any further thoughts on a solution? Still haven't manged to figure this one out... – Chris Nov 03 '16 at 14:33
1

When I saw your question I wondered why you were using Excel formulas and controls to create a dashboard if you had you model in PowerPivot. PowerPivot lets you analyze and visualize data in a more robust and reliable way.

Your initial approach is very complex and it is hard to mantain taking in account that:

  • You have to edit your dashboard whenever a new product be added to your source.
  • Excel functions are prone to errors since they are expecting a specific value as parameters and user could modify it causing errors.
  • PowerPivot calculations are performed faster than Excel functions, specially for large datasets.
  • You cannot offer much interaction with the data to your user.

This is the Dashboard I'd build using Pivot Tables conected to your PowerPivot model.

enter image description here

DOWNLOAD THE EXCEL FILE HERE

To build this dashboard I used four DAX measures:

This Week :=
CALCULATE (
        [Product Avg Review],
        FILTER (
            ALL ( Calendar ),
            Calendar[Week Ending] <= MAX ( Calendar[Week Ending] )
        )
    )

Last Week =
    CALCULATE (
        [Product Avg Review],
        FILTER (
            ALL ( Calendar ),
            Calendar[Week Ending]
                <= MAX ( Calendar[Week Ending] ) - 7
        )
    )

Positive Movement :=
    (
        CALCULATE (
            [Product Avg Review],
            FILTER (
                ALL ( Calendar ),
                Calendar[Week Ending]
                    <= MAX ( Calendar[Week Ending] ) - 7
            )
        )
            - CALCULATE (
                [Product Avg Review],
                FILTER (
                    ALL ( Calendar ),
                    Calendar[Week Ending] <= MAX ( Calendar[Week Ending] )
                )
            )
    )
        * -1

Negative Movement :=
    CALCULATE (
        [Product Avg Review],
        FILTER (
            ALL ( Calendar ),
            Calendar[Week Ending]
                <= MAX ( Calendar[Week Ending] ) - 7
        )
    )
        - CALCULATE (
            [Product Avg Review],
            FILTER (
                ALL ( Calendar ),
                Calendar[Week Ending] <= MAX ( Calendar[Week Ending] )
            )
        )

With measures working you can create a two Pivot Tables, one for showing positive movers and other one to show negative movers.

Note my Excel UI is in spanish, I hope you don't get stuck with this. Just follow the instructions and search in Google, there are plenty resources about Pivot Tables.

enter image description here

In Rows pane add Product Name, in Values add Last Week, This Week and Positive Movement or Negative Movement (according to the Pivot Table you are building) measures.

enter image description here

Once you have the table built you have have to get the TOP X Product Names.

In each Pivot Table click the Row tag icon filter (The below settings are for Positive Movers Pivot Table):

enter image description here

And use these settings:

enter image description here

Change Positive Movement for Negative Movement when you are filtering to get the Top 5 Product Names in the Negative Movement table.

While you can get the Top 5 product names purely in DAX, I think it is better to use the Pivot Table filter option, leaving it dynamic to any number of top products (what could be a new requeriment in the future) without the need to modify the underlying DAX.

Then you just need to add Conditional Formats and you are done.

Let me know if this helps.

alejandro zuleta
  • 13,962
  • 3
  • 28
  • 48
  • Hey Alejandro, your approach works a treat! My initial reason for not wanting to keep things in the pivot table was the filters take up a lot of room on my dashboard. However, I'll take everything you've done, but keep my dropdown filters and run a little VBA off them to filter the pivot tables. That way I should be able to have the best off both worlds. I really appreciate all of your help with this problem as well as your extensive documentation. Many thanks - Chris! – Chris Nov 23 '16 at 21:16
  • @Chris, I am glad you managed to implement my solution to your needs. You are welcome. – alejandro zuleta Nov 23 '16 at 21:21