0
votes

I have hourly data about sales $ of certain categories (Fruits, snacks etc). I'd like to display the median of daily sales values over a month or an year using the hourly data in the table. So, for each category it needs to sum the hourly values and create a daily value first and then calculate the median

regular pivot does not provide median function. I am familiar with Power pivots but have not used Measures. i tried to create a measure using medianX function, but could not make it work

2

2 Answers

0
votes

Ali,

When you create your measure you will want to use the MEDIAN funciton not MEDIANX

The MedianX would be if you were trying to calculate the median value for a column in your table that did not already exist.

For Example, lets say we have Table1 which has two columns Net Revenue and Net Expense. And the following 3 data points exist for each row in the column.

Net Revenue: Jan-2019 100 Feb-2019 300 Mar-2019 300

Net Expense: Jan-2019 50 Feb-2019 100 Mar-2019 50

Since we do not have a Net Profit column in the table we could use MEDIANX to specify the table we would like to use then write our expression for the column that doensn't exist. In the example above it would go =MEDIANX(Table1, [Net Revenue] - [Net Expense]. This would create a median measure for NetProfit even though the column itself doesn't exist in our table.

In your case, since you are aggregating a column that already exists you can just stick with =MEDIAN.

If you need more clarification let me know!

Best,

Brett

0
votes

First, you will need to add a Calendar table to your data model:

Calendar Table Explained

The Calendar table must have fields you want to group your sales by, such as "Year-Month" and "Year-Quarter".

Then, connect the Calendar table to your Sales table via date fields, to get a structure like this:

enter image description here

With this data model in place, create 2 measures ( I will assume your sales table is called "Sales", and calendar table is called "Date"):

Measure 1:

Total Sale = SUM(Sales[Amount])

It will simply calculate sum of sale amounts.

Measure 2:

Median Monthly Sale = MEDIANX( VALUES(Date[Year-Month]), [Total Sale])

This measure will first sum up sales by Year-Month, and then calculate the median of the sums.

To get median sales by a different period, just replace Year-Month with the desired grouping level, for example:

Median Yearly Sale = MEDIANX( VALUES(Date[Year]), [Total Sale])