How to show previous period sales of items that didn't have sales in current month in Power Pivot? - excel

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:

Related

Excel Pivot table Grand Average that includes 0's in total average

I have a custom Measure in my excel data model so I can calculate Grand Average in a pivot table...
MyMeasure:=VAR T1 =
SUMMARIZE(HC_Data,HC_Data[data date (Month)], "Total HC", [Count of NAME]) RETURN
IF(HASONEVALUE(HC_Data[data date (Month)]), SUM(HC_Data[HC count]), AVERAGEX( T1, [Total HC]))
now, at first sight, this works wonders! BUT, it doesn't take into accounts months with 0's since the source data wouldn't have a record if there is a 0 in the pivot table.
The pivot table will show a 0 since the columns months are based on a full calendar, and pivot set to show 0 when there is no record. so what i need is a way that the custom Measure accounts for 0's.. is this possible?
Create a new table comprising a unique list of entries from the data date (Month) column and create a relationship between this new table and HC_Data. You can then amend your measure to:
MyMeasure:=VAR T1 =
SUMMARIZE( Months, Months[Month], "Total HC",[Count of NAME] )
RETURN
IF(
HASONEVALUE( HC_Data[data date (Month)] ),
SUM( HC_Data[HC count] ),
AVERAGEX( T1, [Total HC] )
)
I have assumed that the new table is called Months and comprises a single column called Month.

Excel Pivot table count number of orders from a customer per year

Excel
I'm creating a pivot table and need a column to describe 'average number of orders' made by customers each year.
I have:
Order date
Customer ID
Year
I'm thinking calculated feild, and using COUNT(Order date) to determine number of orders. But I need to be able to use that to get the average number of orders for each customer.
Any help would be appreciated.
Date set example:
Customer ID Order date
Xh015046 12/04/2016
X7615777 03/06/2016
X10062024 20/04/2017
X7615777 25/06/2016
X7615777 05/01/2017
Xh015046 15/04/2017
X10062024 09/07/2018
X7615777 10/07/2018
Xh015046 11/07/2018
X10062024 12/07/2018
Pivot table I want:
Year Average Number of orders per customer
2016 1.5
2017 1
2018 1.333333333
Within the Data Model (Power Pivot), create a new measure:
AverageOrders :=
VAR MyTable =
SUMMARIZE (
Table1,
[Customer ID],
"Order Count", CALCULATE ( COUNTROWS ( Table1 ) )
)
RETURN
AVERAGEX ( MyTable, [Order Count] )
Amend the table (Table1) and column (Customer ID) names in the above as required.
Then create a Pivot Table within the worksheet with Year in the Rows section and the above measure AverageOrders in the Values section.

Excel - Monthly Average

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.

Need to find the average of all values in pivot table

I have a data table that is pulling all successful contacts by case manager over a period of time. We've created a pivot table of the data that groups by case manager for the rows and by month of the contact for the columns. It counts the appointment IDs to get counts per case manager per month.
My manager wants this data displayed in a chart to easily visualize the data. The part I can't get is she wants the average contacts per month over all the case managers and all the months to be displayed on the chart. Essentially, she wants the average of all the values in the pivot table.
I've played around with power pivot and the DAX functions averagex() and summarize() to get averages in the total row per column, but the ultimate grand total is still the average of the totals.
How can I get the average of all the fields by itself?
Here is the sample pivot table with the totals per case manager per month
Here are the totals using averagex(summarize()) to get counts for the values and average for the totals.
AVERAGEX ( SUMMARIZE ( Table1, [Caseload], "x", COUNTA ( [Client ID] ) ), [x] )
However, the real average I want to see is 34 (all the values averaged together
You need to summarize by month as well to be able to average the way you want.
avg_count =
AVERAGEX (
SUMMARIZE (
Table1,
Table1[Caseload], --Assuming this is what you have on the rows
Table1[Month], --Assuming this is what you have on the columns
"x", COUNTA ( Table1[Client ID] )
),
[x]
)

How can I split weekly data to monthly using Excel/ Power Pivot?

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.

Resources