I'm creating a pivot table that looks at per person analysis vs group average. Trying to create a pivot table, to do a comparison analysis (each person vs the group average) on a month over month analysis. As you can see i have a 4th column titled average, as im not sure how to get the average for the group though per month seeing how the data is spread out.
my test data;
http://www.mediafire.com/file/3yyriggqduw6ldw/file
You can do a sumif/countif on the range for only the year & month
(if would be year=row year and month=row month)
You basically need 2 measure as below-
1.
person_wise_average = AVERAGE(your_table_name[sale])
overall_average =
AVERAGEX(
ALL(your_table_name),
your_table_name[sale]
)
Now just add three column to your table visual - "person name", "person_wise_average" and "overall_average". You should now have all your values in the presentation.
Related
My Data is in weekly buckets. I want to split the number into a monthly number but, since there is an overlap in days falling in both the months, I want a weighted average of the data in terms of days that fall in each of the months. For example:
Now, in the above picture, I want to split that 200 (5/7*200 in Jan, 2/7 in Feb). How can I do that using Excel/ Power Pivot/ Dax Functions? Any help here is much appreciated.
Thank you!
Assuming your fact table looks something like below. Values are associated with the starting date of the week it occurred.
Although it may actually be a more granular data, having multiple rows for each week with additional attributes (such as identifiers of a person, a store, depending on the business), what being shown below will work the same.
What we need to do first is to create a date table. We can do that in "Design" tab, by clicking "Date Table", then "New".
In this date table, we need to add a column for starting date of the week which the date of each row is in. Set the cursor to "Add Column" area, and input following formula. Then rename this column to "Week Start Date".
= [Date] - [Day Of Week Number] + 1
Now, we can define the measure to calculate the number allocated to each month with following formula. What this measure is doing is:
Iterating over each row of the fact table
Count the number of days for the week visible in the filter context
Add the value portion for the visible days
Value Allocation := SUMX (
MyData,
VAR WeekStartDate = MyData[Week]
VAR NumDaysInSelection = COUNTROWS (
FILTER (
'Calendar',
'Calendar'[Week Start Date] = WeekStartDate
)
)
VAR AllocationRate = DIVIDE ( NumDaysInSelection, 7 )
RETURN AllocationRate * MyData[Value]
)
Result in the pivot table will be looking like this.
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
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:
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])
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
When displaying prior month sales, I noticed that items with no sales in current month are missing in the Pivot Table output of the data model. However, the grand total sales includes sales of those missing items.
I created a small data model to replicate the issue: 2 tables (1 sales table and 1 calendar table) and it has 1 single DAX formula:
Previous Month Sales:=CALCULATE(sum([Sales]),PREVIOUSMONTH(Sales[Date]))
In the output table, I would have expected 1 more item row for Potatoes, with 0 sales in current month and 31 in previous month.
Is there a way to force-show Potatoes item in the pivot table above when selecting date 24/03/2019? Can this be achieved with DAX formulas?
You need to use the Date field from your Calendar (Date) table, for Time Intelligence to work as you intend:
So change your Previous Month Sales measure to:
Sales Previous Month:=CALCULATE (
SUM ( Sales[Sales] ),
PREVIOUSMONTH ( Calendar[Date] )
)
I'd also recommend creating an Explicit Measure for Sales:
Sales Total:=SUM ( Sales[Sales] )
Now you can recreate your pivot output, using Date field(s) from Calendar in your slicer / filter, and you should get the output you require:
I have a table in SSAS tabular mode that shows how individual pieces of products moved through different sections of a production line:
Product_ID, section_ID, Category_id (product category), time_in (when a product entered the section), time_out (when the product exited the section)
This is how the input table looks like:
I would like to write a measure in DAX that can show me the stock of each section and product category day-by-day as shown below by counting the number of distinct product ids which were in a particular section on that day.
I'm using SQL Server 2017 Analysis Services in Tabular Mode and Excel Pivot Table for representation.
Create a new table that has all of the dates that you want to use for your columns. Here's one possibility:
Dates = CALENDAR(MIN(ProductInOut[time_in]), MAX(ProductInOut[time_out]))
Now create a measure that counts rows in your input table satisfying a condition.
ProductCount =
VAR DateColumn = MAX(Dates[Date])
RETURN COUNTROWS(FILTER(ProductInOut,
ProductInOut[time_in] <= DateColumn &&
ProductInOut[time_out] >= DateColumn)) + 0
Now you should be able to set up a pivot table with Category_id on the rows and Dates[Date] on the columns and ProductCount as the values.
I have a table of daily data in Excel. Let's say it's daily stock return data that looks like:
Date, DailyReturn
1/1/2001, .021
1/2/2001, .005
1/3/2001, .0034
1/4/2001, .013
....
12/31/2001, .004
The data is in a table on one of the sheets. Let's call it TableOfData. I've added a pivot table on another sheet, and I've added the date as the Row Labels. I've also added grouping by year and month to the rows. Now it is easy to add the average and stddev of the returns for each month, but I would also like the total return for the month, which would be calculated as Product(DailyReturn + 1) -1
I can add a calculated field called DailyReturnFactor, which is simply DailyReturn + 1, and I can add the Product of that field to the values and the pivot table shows the return for each month, except that I still need to subtract 1. That is where I'm stuck. Any ideas on if this is possible? The other issue is that I would like to do other sets of calculations as well, e.g. kurtosis.
Note I'm using Excel 2007.