MDX syntax for DAX measures calculated with AVERAGE()

折月煮酒 提交于 2019-12-06 07:17:20

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.

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.

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.

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):

And use these settings:

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.

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?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!