Get the average monthly value from 2 SP List columns and display in new column - sharepoint

I need to calculate the average value for each month. Currently I have 2 columns "DATE" (date value e.g 01/01/2010) and AccOpen (number value). So for all dates within January I need to return the average value of all numbers contained in the corresponding AccOpen rows for January dates.
Is it possible to use the CALCULATED option and input a FORMULA that will return the average for all itmes within each months period (when adding a column to the list ?
DATE ACCOPEN AVERAGE
01/01/2010 2 2
02/01/2010 2
03/01/2010 2
04/01/2010 2
01/02/2010 2 2
02/02/2010 2
03/02/2010 2
04/02/2010 2

You're not going to be able to do this OOTB without writing event receiver code (or other custom code running in a batch mode).
To get you started
MSDN - How to: Create an Event Handler Feature
Event Handlers : Everything you need to know...
This will need to hook into the list item update and then consolidate your list into a separate summary list with the calculations you need.
The brute force approach would be to run the calculation afresh for every item in the group when an item is inserted/updated.
A smarter approach would be to just update the delta (the difference between the old and the new record) which is easier to do if you store components of the calculation - so in your case
Month - NumRecords - TotalValue
and work out the Average on the fly (as its easy to delta the NumRecords/TotalValue but impossible to apply it directly to the average)
One 3rd party web part which may fit your need is PivotPoint - it allows you to do things like sum/count/avg over groups like Month & Year (disclaimer - I work for the company)

It is not possible to query anything other than the current item when creating a formula field.
The only way to do this is to create custom code either within an event handler for the list or external code that processes items in the list and updates a "average" field when required.

Create a calculated field to give you the year and month, for example: 2011-07. Then modify your list view to group on the calculated field. When editing your view, there is also an option to display totals, I believe you can set this to average for your AccOpen column. If you're not interested in the details, you can choose to collapse all groups by default.

Related

Difference between rows in the same coulm for values which met specific conditions

here's my input and my desidered output. Problem Is: I have a columns for product, price, and date and I want to build a cross table where I can see the price of the day before for every product.
How can I calculate column d-1 (day - 1) in my data table? Should I use Intersect/Over functions? What If I want to calculate my d-1 column on-the-fly in a cross table?
You have some options here, depending on how you want to display everything.
If all you want is an overall snapshot of how it changed between Today and Yesterday, probably the simplest thing to do is the following:
Avg(If([DATE]=Date(DateTimeNow()),[Price],NULL)) as [Today's Price],
Avg(If([DATE]=Date(DateAdd("day",-1,DateTimeNow())),[Price],NULL)) as [Yesterday's Price],
Avg(If([DATE]=Date(DateTimeNow()),[Price],NULL)) - Avg(If([DATE]=Date(DateAdd("day",-1,DateTimeNow())),[Price],NULL)) as [d-1]
This can be very useful for a dashboard or summary, and if you replace the "DateTimeNow" component with a Document Property controlled by an Input field, this can quickly show your user the change on a specific day.
The Over functions could still be quite useful, especially if you're using a date hierarchy of some form.
It will update on the fly to accommodate the columns grouped across the top, so if you're displaying by date, you can see how it's been changing each day, and if you're displaying by month, you can see it that way instead.
Avg([Price]) as [Avg Price],
Avg([Price]) - Avg([Price]) OVER (PreviousPeriod([Axis.Columns])) as [Avg Price Change]

Spotfire- limiting Information link colum expression

I have a column of data [Sales ID] that bringing in duplicate data for an analysis. My goal is to try and limit the data to pull unique sales ID's for the max day of every month in the analysis only (instead of daily). Im basically trying to get it to only pull in unique sales ID values for the last the day of every month in the analysis ,and if the current day is the last day so far then it should pull that in. So it should pull in the MAX date in any given month. Please how do i write an expresion with the [Sales ID] column and [Date ] column to acieve this?
Probably the two easiest options are to
1) Adjust the SQL as niko mentioned
2) Limit the visualization with the "Limit Data Using Expression" option, using the following:
Rank(Day([DATE]), "desc", Month([DATE]), Year([DATE])) = 1
If you had to do it in the Data on Demand section (maybe the IL itself is a usp or you don't have permission to edit it), my preference would be to create another data table that only has the max dates for each month, and then filter your first data table by that.
However, if you really need to do it in the Data on Demand section, then I'm guessing you don't have the ability to create your own information links. This would mean you can't key off additional data tables, and you're probably going to have to get creative.
Constraints of creativity include needing to know the "rules" of your data -- are you pulling the data in daily? Once a week? Do you have today's data, or today - 2? You could probably write a python script to grab the last day of every month for the last 10 years, and then whatever yesterday's date was, and throw all those values into a document property. This would allow you to do a "Values from Property".
(Side Note: I want to say you could also do it directly in the expression portion with something like an extremely long
Date(DateTimeNow()),DateAdd("dd",-1,Date(Year(DateTimeNow()), Month(DateTimeNow()), 1))
But Spotfire is refusing to accept that as multiple values. Interestingly, when I pull the logic for a StringList property, it gives this: $map("${udDates}", ","), which suggests commas are an accurate methodology, but I get an error reading "Expected 'End of expression' but found ','" . Uncertain if this is a Spotfire issue, or related to my database connection)
tl;dr -- Doing it in the Data on Demand section is probably convoluted. Recommend adjusting in SQL if possible, and otherwise limiting in the visualization

SSAS Calculated member that knows if the user is using the report filter

I am trying to write a calculated member which acts differently depending on whether the user is filtering by that member or has it dragged down as rows or columns on their pivot table (using Excel).
The rules are:
1. If the user is using the date dimensin as a Report Filter in Excel, then the calculated member should get the maximum date out of all dates that they are filtered by.
2. If they have the date dimension as rows on the pivot table, then I need to apply ClosingPeriod and some other logic.
Please try this. The idea came from here.
Basically the dynamic named set represents what's in the report filters. And the EXISTING keyword trims the list of days down to the filter context of the current cell letting you detect say if one month is on rows. Compare counts and you can detect what the user did.
CREATE HIDDEN DYNAMIC SET CURRENTCUBE.SelectedDays as
[Date].[Date].[Date].Members;
CREATE MEMBER CURRENTCUBE.[Measures].[My Calc] as
CASE
WHEN SelectedDays.Count > {existing [Date].[Date].[Date].Members}.Count
THEN Tail({existing [Date].[Date].[Date].Members},1).Item(0).Item(0).Name
WHEN SelectedDays.Count < [Date].[Date].[Date].Members.Count
THEN Tail(SelectedDays,1).Item(0).Item(0).Name
END
Performance is going to not be good. And I suspect users will be confused with the results of your calc. If you want to describe the business scenario more I can maybe recommend a better approach.

DAX Rank by Date

I am Counting on Distinct ID's in a column - this is leading to the sum of the subtotals not equalling the grand total as follows:
What I want to do is rank the Payment Dates in cronological order and select ONLY the highest date to display. In the example above the Grand Total won't change, but the Townville row will not show a Distinct Student Count.
This is a very specific requirement and I'm assuming there's an easy way to do it in DAX - I've tried playing around with both RANKX and MAX but am no closer to solving this.
One last thing - the Rank must be contextual to the Time Filter selected by the user (so if they select 2015 it'd give the second record Rank 1 and the top record wouldn't show. If they select May 2015 it'd give the top record Rank 1 and the second record wouldn't show)
I think this is what you are looking for - I added a calculated column to the PowerPivot model that provides a rank based on the Last Payment Date and the Name of the Student. It will rank the earliest payment for any student as a 1.
The code for the column is as follows:
=RANKX(FILTER(Table1, [Student Name] = EARLIER([Student Name])), [Last Payment Date])
... assuming your table is named "Table1"!
The FILTER is the key that limits the ranking to dates belonging to students with that name only.
Update for Multiple tables
To set up relationships between the tables, go to the "Diagram View" of the model, available in the Home tab of the Power Pivot window.
You can drag fields from one table to the other to create relationships. This will only work if at least one of the fields is unique - it's a good idea to think of the model as a dimensional model, with a tables that acts like a fact and other tables around it that act like dimensions.
From the comment, I would try to get the Payments to act like the fact, and have it link to the Community and Student tables. in this case, you could then have the following code:
=RANKX(FILTER(Table1, Related('Students'[Student Name]) = EARLIER('Students'[Student Name])), [Last Payment Date])
This calculated column would be on your Payments Fact table, and it uses a lookup to a related field.
Note that in this specific case, it would be easier to just run the filter over your Student ID field that is used to lookup the Student name.

Have VBA for Unique items in multicolumn range, how to filter multiple rows on previous results?

Intro
I'm trying to enhance a basic planning sheet (see below) with additional sorting.
The first column lists the resources. Each week has 2 columns representing 20 hours per column.
Example readout;
In week 30 Aron works 40h on project A. In week 31 he works 20h on project A and 20h on project B.
Jeff does not work in WK30 and works 40 on project C in WK31
My Goal
Generate a unique list of projects over the weeks
Be able to filter based on project name and get only the rows of the resources working on that project. (No specific need to filter out the other projects in the same row. So if I filter on project "A", I want to only see the rows of Aron and Dave)
What I have
Basically item 1 is covered as follows:
The 2nd column (Projects) is an array-formula generated by a VBA function (taken from here) that returns all unique items in a multi column range. The cell formula looks like this, where the second argument of UniqueItems() determines if we only return the number of unique items (TRUE) or a list of all unique values (FALSE).
=TRANSPOSE(UniqueItems($C$4:$H$6,FALSE))
What is missing
Item 2 of my goal list is missing. If I currently select the filter option for Projects (see screenshot)
and filter on Project A, then I only get row 5 and not also row 4.
How would I go about filtering this properly?
VBA code is allowed or pointers to which regular formula functions I should use. A complete different solution with the same results is also fine. I thought about pivot tables, but I think it cannot handle empty cells around the range which is common if there's no work for that resource.
The sheet used can be downloaded from here
IMHO, you will be much better off creating a worksheet serving as a normalized database table with one row per the following columns: person, week, project. Lastly, a final column for the number of hours (and optionally, a cost for those hours customized per worker as needed)
Then use a pivot table to build the view you posted (or any other reporting view you need).
This will let you create multiple pivot tables that easily answer questions like:
how many hours are planned for project X in total? by a certain date?
how many total hours are planned for each worker per time period - who is over/under utilized?
how many total hours are planned for each worker per project?
etc.
Keeping the data separate from the reports is safer, and more modular - I wouldn't want a VBA bug to have the potential of corrupting/deleting raw data.

Resources