Create calculated field based on the max of another value in Excel pivot table - excel

I have a pivot table that summarized data from multiple lines of hours on different accounts an employee has planned to work.
I want to have a calculated field that shows the difference between the hours the employee has planned to work and the number of hours authorized for an employee to work for the year.
The number of hours authorized is different for certain employees.
I am currently using a helper field in my pivot table and xlookup to another employee authorized hours table to add the authorized hours on each of the lines in the source data.
I can get the table to display the correct authorized hours using the "max of" but I don't know how to calculate the difference by either modifying the table, or using calculated fields.
Any ideas appreciated.

Related

Pivot Table project - Avoid using many INDEX and MATCH functions that make Excel crash

I need some help with an Excel Project that's giving me headaches. I succeeded to achieve everything I wanted but the result is too heavy for Excel and it crashes all the time. I'm over-using the INDEX and MATCH functions on large tables (50 000+ lines) and Excel doesn't like it. I'm looking for a way to do the same thing in a lighter way for Excel.
Here's what I achieved : I created a report that helps me analyzing my employees's performance VS their billing targets. To create such a report, I used a Pivot Table.
That Pivot Table needs this information as its source :
Each sales that every employee made (amount in $ and date)
The hourly rate of each employee (which changes for every period, see TABLE1 below)
The billing target for each employees (which changes for every period, see TABLE1 below)
Here's my setup. I have 3 tables :
TABLE1 (See attached image) - A table where I manually input data for each of my employees (hourly rate and billing target). Their billing target and hourly rate change every period. So, each period has a different line and I indicate the first day of the period and the last day of the period.
TABLE2 (See attached image) - Table that contains sales data exported from another software I use. Each line represents an amount sold by an employee to a customer on a specific date. This table is pretty heavy and contains more than 50 000 lines. Moreover, the last 2 columns of this table use Index and Match functions to get the right hourly rate and the right billing target from TABLE1. That means that each of those 50 000 lines uses the INDEX and MATCH functions twice… This part is too heavy for Excel and I need a workaround.
Moreover, TABLE2 is getting refreshed every few days with new data coming from my other software (an ERP). So the solution I need to find must take that into account and must be permanent (I try to avoid steps that will have to be done everytime I refresh TABLE2 with new data).
TABLE3 - A Pivot Table that uses TABLE2 as its data source. I use the slicer to select the name of an employee and a timeline to specify which months I want to display. Then the Pivot Table shows my employee's statistics grouped by months. The main statistic is the amount of "billed hours" for each employee, which is in reality the amount of sales made by that employee, divided by their hourly rate on a specific date.
My thoughts :
It is absurd that TABLE2 uses that many INDEX and MATCH functions. For example, if Employee1 made 500 sales between 2020-07-01 and 2020-07-31 (the same month, thus the same period, thus the same hourly rate and billing target), there will be 500 different lines that will use INDEX and MATCH to get the same hourly rate and billing target from TABLE1. That leads to a lot of duplicated calculation and a lot of duplicated data.
Would it be possible for a Pivot Table Calculated Field to use INDEX and MATCH in its formula? And would it be lighter for Excel to do so?
Another way would be to add, at the bottom of TABLE2, 12 lines per year (1 for each month) for every employee where I would write their hourly rate and the billing target. That way, the Pivot Table would be able to display an hourly rate and a billing target for each month, for each employee. That solution would work and would be lighter for Excel, but it would create a high risk of making mistakes while manually inputting the data.
I'm open to all suggestions including VBA!
Thank you very much for your precious time!
EDIT : FORMULA
As requested, here's my INDEX AND MATCH formula that is in TABLE2 and gets the hourly rate from TABLE1 :
=INDEX(TAB_Employee_Data[[#All];[Hourly_Rate]];MATCH([#[Date (Cell)]]; IF(TAB_Employee_Data[[#All];[Name]]=[#[Employee(Cell)]];TAB_Employee_Data[[#All];[First day of the period]]);1))
TAB_Employee_Data is the tab that contains "TABLE1".
I translated the names of the fields since all my work is in French.
This formula does the following : it searches the name of an employee in TABLE1 and finds the period which fits the date of a line in TABLE2.
Also, to work properly, I need to sort the lines of TABLE1 in chronological order.
TABLE 1 :
TABLE 2:

Count of customers scheduling service dates in consecutive years

I am brand new to Spotfire (using 7.7) and am hitting a roadblock on a simple task so am hoping for some assistance.
I need a count of customers that are scheduling service dates in consecutive years.
Since users will be using different date filters I created a MaxServiceDate calculated column to give me the max date depending on the filter and from there subtract a year to give me a PreviousYear calculated column.
Then my thought is then do a distinct count of all CustomerIDs which have a ServiceDate that match the MaxServiceDate and PreviousYear. The issue I'm running into is I don't know how to group by or fix the CustomerID in order to loop through the ServiceDates and check if they have dates matching my criteria.
Thanks for any help.
Sample data:
You can create a secondary table with a pivot transformation having the max(ServiceDate) and customer ID. The join that table back with your original so that you have the maxdate for each customer on your main table. Then do a calculated column based on the Max(ServiceDate) and Service date to determine if > 365 days.
Pivot Transformation
I think a calculated column like the following would meet your needs:
If((Max(Year([ServiceDate])) over (Intersect([CustomerID])) - Min(Year([ServiceDate])) over (Intersect([CustomerID])) + 1)=UniqueCount(Year([ServiceDate])) over (Intersect([CustomerID])),"good","bad")
For each customer, take their max service date year and subtract their min service date year and add +1. This number should match the number of distinct years associated to that customer's service dates.
This will tell you if a particular customer (at least while you had that customer) had service done in consecutive years or not.

Excel Pivot Table Inquiry

I have a pivot table with imported data from a raw data list, which is also filterable between 4 different months. I want to show, in the same pivot table, the averages of last month, the current month, and the average of all four, but every time I change one column, the others change as well. How do I get them to be accurate and act independently? Would offset be the best option. I know this question is rather confusing, but I'm not sure how to even ask the question. Thanks for your time.
You can create fórmula the last month based on you Date field.
First you need to create a formula on your data source and named
"last month":
=IF(AND(A2>=EDATE(DATE(YEAR(TODAY()), MONTH(TODAY()),1),-1), A2<=EDATE(DATE(YEAR(TODAY()), MONTH(TODAY()),DAY(TODAY())),-1)),D2,0)
"the current month":
=IF(AND(A2>=DATE(YEAR(TODAY()), MONTH(TODAY()),1), A2<=DATE(YEAR(TODAY()), MONTH(TODAY()),DAY(TODAY()))),D2,0)
"the average of all four":
=IF(AND(A2>=EDATE(DATE(YEAR(TODAY()), MONTH(TODAY()),1),-4), A2<=DATE(YEAR(TODAY()), MONTH(TODAY()),DAY(TODAY()))),D2,0)
After you create the fórmula you can able to add it to your pivot table as Sum, Average etc...
Example:

Calculating Weekly Average by user given daily data input in excel pivot table

So I started using Pivot Tables a few weeks ago, but I'm pretty decent at Excel otherwise. I hit an issue that should be an easy fix and I don't see it. I have a document that is tracking Key Performance Indicators for my warehouse packing department. I have 2 tabs in the document that matter (Input Log, and Analysis).
Input log is basically copied from a report generated from my warehouse system. Gives me a USER, DATE, HRS WORKED, ORDERS PACKED, ITEMS PACKED. Using a pivot table I want to see the average hours worked by week for each user.
Currently I can only see the Sum of the hours works and the daily average. How do I also see the weekly average?
[InputLogData][2]
I was able to get the workbook hosted on google drive Packing KPI Workbook
If you create the pivot table, but select to "add to data model",
you will see, in the "Value Fields Settings" selection, a Distinct Count item.
You can then do a Distinct Count of the WE column, and add a column to divide the total hours worked by User, by the total number of Weeks. (See the formula in D4: =B4/C4 )
EDIT: If you want to have the results within the Pivot Table itself, you can add a few calculated columns to your input log.
WE per User is the Unique number of weeks each user works. This formula is an array formula and must be entered by holding down ctrl + shift while hitting enter. Excel will place braces {...} around the formula seen in the formula bar:
=SUM(--(FREQUENCY(IF(User=D2,WE),WE)>0))
Hrs Worked This Wk is the hours worked in the week by the user. This is not really needed, but is in there for when I was troubleshooting the calculations.
=SUMIFS(Hrs_Worked,WE,A2,User,D2)
This will be used to calculate the average for the AvgHrs/Wk column:
=SUMPRODUCT((User='Input Log'!$D2)*Hrs_Worked/WE_Per_User)
This can then be used to create the Pivot Table:
In the Pivot Table, the
Total Hrs is the SUM of Hrs Worked
Hrs-Daily is the Average of Hrs Worked,
Weekly Hrs is the Average of AvgHrs/Wk

query in a powerpivot table to do a group by

I have a table called "purchase" with the following data:
year month time day_week name provider service purchase revenue
I am using this data to make a pivot table. Then I have another table called "active":
name provider service description month year number_active
I used this data to create a separate pivot table.
Now I need a third pivot table with something like:
number_active/revenue
and slice it vertically to by year. The problem is that I cannot create a relationship between the table because in Purchase I have the services by day and hour and in Active I have the services by month. I think I need to create another table that is a view of Purchase grouped by month.
I tried the following :
home -> From Database -> From analysis services or PowerPivot
But i have a error:
I'm not sure where to go from here.
How can I make this view grouped by month?
I don't think you need to create a new view of summarized data as a source. You just need to be able to summarize by date, and you can do this by adding a date dimension.
You can download one for free from the Windows Azure marketplace.
Once you have your date table, add a calculated column to the Active table in your Power Pivot model called Date that is =[Month]&"/01/"&[year]. Then change the data type to date.
Then do the same thing to your Purchase table. Next, create relationships from Active[Date] to Date[DateKey] and from Purchase[Date] to Date[DateKey].
You could make all of this go down to the time level and related it there instead (Power Pivot will assume midnight if you don't specify a time in your date column). But I'm simplifying since that is not needed for this one scenario.
Next make your two base calculated measures
Number Active:=Sum(Active[number_active])
Total Revenue:=Sum(Purchase[revenue])
I'm not sure what your number active means, so I'm assuming it is just a sum. You can adjust this calc if this is not the case.
Then make your final calculation: Revenue Per Active User:= [Number Active]/[Total Revenue]
Then you should be able to pull month and year into a pivot table along with this new calculated measure and your original measures (number active and revenue).

Resources