Create View Eliminating Records of X Date - dynamics-crm-2011

I am trying to create a view to find records of a certain date but the results are not what I want for an end result.
To start I want to view records who's start date is 3 weeks out. Simple enough.
.... StartDate | Next X Weeks | 3
This gets my records that are 3 weeks out cool......but it also returns records that are 1 week and 2 weeks out...which I don't want....but I don't see any way to exclude when working with dates? For example this psuedo query....
.... StartDate | Next X Weeks | 3
.... StartDate | ! Next X Weeks | 2
.... StartDate | ! Next X Weeks | 1
Now I haven't dug into seeing if this can be done by writing FetchXML directly....I figured Msoft would have addressed this by now and incorporated it into the UI...but perhaps I am wrong?

The UI only incorporates a subset of available operators. You could, However, use a dynamically built fetchxml which allows you to use the greater then operator and a specific date (today + 3 weeks).
But this means you need to create your own view using something like the following using a webresource or an iframe.

Well unfortunately this logic isn't capable with FetchXML alone http://msdn.microsoft.com/en-us/library/gg309405.aspx
The "not" concept doesn't apply to dates, otherwise you could use the AND logic you specified above.
You can however create a web resource and then query the data you want via JCL or another library. Then you can parse the results to filter the first two weeks via JavaScript.
Or you can create the view with 3 weeks and sort by the date descending. This leaves extra noise at the end of the view, but may suffice.

I am very grateful to Paul & ad1ka's responses and they definitely taught me something new. However both were not quite what I was looking for and that I'm quite confident that is only because of my poorly worded question.
Here is what I ended up doing and feel free to comment / criticize.
I created a DateConmstants entity and added five records (there will be more). (The records have a name, date, and corresponding view name that it applies to).
I then created a maintenance workflow that executes every night to update the dates. For example record 1 is always to be 2 weeks out so the nightly workflow will update the record with the process exec time + 14 days.
I then created the views needing dates adjusted...(with bogus dates for now)
with OnOrAfter and OnOrBefore thus creating a date "sandwich".
I then created a custom workflow that updates these views. It takes an input array of the views to be updated and the records from dateconstants that match the view.
The workflow then finds the view, loads the fetch into an xml. Using the xml find single node I find the OnorAfter and OnOrBefore values and update them. Then push the xml back to to query definition. Update and publish changes.
Finally this is scheduled as part of the afore mentioned nightly maintenance job.
So every day the users have views displaying the correct records with nothing extraneous.
FWIW

Related

Dynamically Remove Columns In Power Query By Header Dates

I have a query table of data that has been merged in Power Query. The result is monthly percentages for each person for two years that looks like this. I would like to dynamically remove months from the table when the month is over. So, starting August 1st, July would be removed from the power query table when I refresh it.
Merged Query Table:
Name
Jul-21
Aug-21
Sept-21
Bob
.10
.20
.10
Amy
.30
.40
.10
I've looked through StackOver, and there is one post that is similar to what I want to accomplish: Table.RemoveColumns based on the date
The code suggested in that post to remove column headers older than three years was:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
final = Table.SelectColumns(Source, List.Select(Table.ColumnNames(Source),
each try Date.From(_) >= Date.AddYears(Date.From(DateTime.FixedLocalNow()),-3)
otherwise true))
in
final
I went into the Advanced Editor in Power Query to try to adjust it to what I was trying to do, but the code does not work and no columns are removed. This is even before adjusting the code to not remove the current month.
let
Source = Table.Combine({Merge1, Merge2}),
final = Table.SelectColumns(Source, List.Select(Table.ColumnNames(Source),
each try Date.FromText(_) >= Date.From(DateTime.FixedLocalNow())
otherwise true))
in
final
I have tried both each try Date.From(_) and each try Date.FromText(_), neither of which removed any columns. I have not altered the Date.From(DateTime.FixedLocalNow()) part of the equation in any of my tests.
I have tried to search for online resources to understand how this code works as well as used Microsoft's support site to learn about Table.SelectColumns and List.Select, but I have yet to find a good resource that can break down how to understand the above code, so it makes it difficult for me to understand what changes I need to make to get it work.
So far, I understand that the List.Select is determining the columns that will be included in the Table.SelectColumns function. List.Select is creating a list of all the column headers and then measuring their text (transformed by the Date.FromText(_) function into a date) against the current date using the each try and the otherwise is catching all the non-date headers and making sure they are included as well.
But I don't understand why the equation isn't removing any the past date columns or how to adjust the function (once it works) to not remove the current month. I would appreciate any assistance with both of these questions. I can share a link to the full spreadsheet if that would be helpful.
How about
Table.SelectColumns(Source, List.Select(Table.ColumnNames(Source),
each try
Date.StartOfMonth(Date.FromText(Text.Start(_,3)&"/01/"&"20"&Text.End(_,2)))
>= Date.StartOfMonth(Date.From(DateTime.FixedLocalNow()))
otherwise true))

How to Generate a Burndown by Month

I have a dataset of action tracking records with due dates. I've been asked to generate a burndown curve, which I can do pretty simply in Excel, but I'm stumped on how to put this in a WebI report.
I created a variable to convert the due date for the records to yyyy-MM, so I can group them by the month they're due and count them. Then, I was able to add a runningsum of those counts in my crosstab.
[
The element that I'm missing is being able to refer to the total count of records (the total outside the column grouping of the crosstab) to subtract the running sum from.
Suggestions?
You need to deal with Calculation Contexts in order to do this. Here are a few good resources...
Removing the Confusion from Calculation Contexts
Calculation Context Part I: Overview
The More Things Change... (de facto Part II to Part I above)
To answer your question and show my work I created a free-hand SQL query using the SQL in this dbfiddle. Put into a crosstab with a running sum I get what you have in your example...
Next I created a variable called Var Report Total defined as...
=Sum([Act Count]) In Report
Then I created another variable called Var Remaining to calculate the difference...
=[Var Report Total] - [Var Running Sum]
And there you have it...

categorizing documents depending on their date fields

I've been stuck with an annoying problem for a while that I can't fix. I have a field in all of the documents that represents time- a date in format dd.mm.yyyy.
What I'm trying to do is to categorise them- Show the documents that have todays date, that will have todays date in closest 7 days, etc.
Here's the code (formula for the categorized field) that I have:
#If(#Today > pi_due_date; "Late docs"; #Today=pi_due_dat; "Todays docs";((pi_due_date - #Now)/86400)>0 &((pi_due_date - #Now)/86400)<7;"This weeks docs";"Future docs")
Everything was fine until today (after 12:00 PM) I noticed that this part: #Today=pi_due_dat; "Todays docs"; does not work, it does not return the document in the "Todays docs" category. Pretty much the same thing is happening to all the other categories and I don't understand what is causing this problem.
pi_due_dat is missing the 'e' at the end.
Assuming it is more than that, though, you'll want to make sure that you are only comparing the dates and not a date/time.
Try #Date(pi_due_date) = #Today instead.
I would like to point out that using #Today or #Now in a view (selection criteria or column value) will create serious performance issues, as the view will be constantly re-indexed. It will affect all applications on that server as well.
You may want to rethink the design, perhaps have a scheduled nightly agent that set a flag on the documents to indicate how they are boing categorized.

Amazon Cloud Search - get places by time and date

I am using Amazon CloudSearch to store a large set of places.
Each place has a opening time and a closing time, for each day of the week.
I need to retrieve places by current time. How do you suggest to model the index?
I am thinking to solve the problem by creating 7 text indexes in which I specify, for each day of the week, the valid hours.
For example, if a place is opened from 9 am to 13 am, in the index "monday" I will write the string "9-10-11-12". Then, filtering by bq=monday:'10' or bq=monday:'16' I will have only the places that at the specified time are opened.
Any other idea? My solution seems working but would suggest me another approach?
First, I wouldn't use multiple indexes.
You could use your approach, but just make the time in hours from the start of the week. So, Monday would be 0-23, Tuesday 24-47, etc. Or you could just have 7 fields, "monday_hours", "tuesday_hours", …
You could also use uints, instead of strings. Not better, but different, might be worth benchmarking.
With uints you can use range queries. If the document contained the fields "open" and "close" and you want to know if it's open between 10 and 12.
&bq=(and open:..12 close:10..)
One issue remaining is that CloudSearch's range searches are inclusive of endpoints. So I think this will show a false positive if the store opens at twelve. Technically, the ranges overlap, but not usefully. To fix that, I'd do two things. First, I wouldn't go by hours, I'd use minute-of-the-day as the value in the field (0 to 1439). Then add one to the starting range, and subtract one from the end.
Using uints will perform differently from using text fields. I'd definitely benchmark them to see which one works better for you.

Any solution to the Today Calculated Column problem is SharePoint?

I would like to be able to use today's date in a calculated column in a SharePoint list to, for example, determine whether a task is overdue. There is a well-documented trick that involves creating a dummy column named "Today," using it in a formula, and then deleting it, thereby "tricking" SharePoint into using the Today function.
The problem is that this method does not work reliably -- the calculation is not dynamic; it is only made when the item is saved, and therefore the Today "column" effectively becomes the Modified Date. (This is probably why SharePoint won't let you use the Today function in a straight-forward way.)
Has anyone found a solution that works? I know I can use javascript to get the actual date on the client side and display colors, flags, whatever, but I am looking for a "server side" solution.
For reference, the Today column trick and its problems are described fairly well at these two posts and associated comments:
http://blogs.msdn.com/cjohnson/archive/2006/03/16/552314.aspx and http://pathtosharepoint.wordpress.com/2008/08/14/calculated-columns-the-useless-today-trick/
There simply isn't a work around for this. As the values for the list are stored in the database and returned "as is" to other featurs such as the search crawler, a dynamic field cannot be created.
It is possible to create a custom field that will display the value using todays date in its calculation.
In addition to Christophe's (PathToSharePoint)'s article this also covers the Today trick and why it doesn't work
The Truth about using Today in calculated columns
There are a number of fudges, probably the best one is Dessie's console app (mentioned above by MNM)
Dynamically updating a SharePoint calculated column containing a Today reference
Its good but its not perfect, for example you may have to worry about different timezones.
Before going down this route you should ask yourself if you really, really need to do this. For example :-
If you want a countdown (days overdue/days left to complete a task) then you can use SPD and a XLST Data View web part
If you want a view to show overdue items or items created in the last X days ec then you can use [Today] in a views filter 2
If you create a Today column it needs to be updated. You can do that with either a timer job or by placing a jquery script on a page that is hit by the user. The script could call SPServices.SPUpdateMultipleListItems to do the update. Pass a CAML clause so that you only update the list items where the Today value needs to be updated, e.g. once per day.
My advice is to create your on field that does this calculation for you and then reference it in your SharePoint list. Not a simple implementation but it would work.
I have been looking for a solution either, still no luck.. The Today column trick has the limitation of not being dynamic.
I do have one suggestion though, why don't we create a timer job that will update a certain a certain column with the current date every day at 12 AM. I know some of you all might think it an over head. Just my suggestion :D!!
I came up with a very rough, but working solution to this problem without having to do any coding. I'll explain both how i made the today column and how i worked that in to an overdue column, becuase that column was a pain to find out how to do as well.
First, I made a column named "today" (gasp!). Next I made a column named "Days Overdue". I then opened up sharepoint designer and created a new workflow. I set it to run every time an item is edited/updated (keep in mind I turned off versioning for this list, otherwise I would have had to resort to coding to avoid a bunch of useless data building up on our server). I set the actions to simply store the modified date in a workflow variable, then change the value of the today column to that variable. although the modified column is a date/time and my today column is just a date, it transfers just fine. I then set the workflow to pause for 2 hours. you can set this to whatever amount of time you want obviously, it will just change the latest possible time for your today column to update, i.e. 2AM in my case.
on to the days overdue column. this is the code for that guy -
=IF([Due Date]>Today,"None",IF([Date Closed]=0,Today-[Due Date],IF([Due Date]>[Date Closed],"None",IF(Today>=[Date Closed],[Date Closed]-[Due Date],IF([Due Date]<Today,Today-[Due Date])))))
This shows the days overdue in number form in days, or if its not overdue, it shows "None". You can use either a number format or a string format, but NOT A DATE FORMAT. Well, I hope this helps anyone who is running into this problem and doesn't want to have to delve into coding.
EDIT: I forgot to say that in the code above for the days overdue column, I put in that if today is past the date closed, to use the date closed minus the due date instead of today minus due date, to ensure that the calculation doesnt keep occurring after an item has been closed. you probably would have noticed that in the code, but i felt i should point it out just in case.
EDIT 2: The code I had in before my 2nd edit for my calculated column didn't calculate the days overdue properly after an issue had been marked "closed." I put in the updated code. The last part of the code doesn't make sense, as it is the same logic as the beginning, but it worked so I didn't want to take any chances! :)
Peace.
I've used the following and had no problems.
Field Name: Overdue
Field Type: Calculated
Data Type Returned: Yes/No
Formula:
=AND([Due Date]<NOW(),Status<>"Completed",[Due Date]<>"")
Here is a workaround:
Create a date column called Today.
Use this column in your calculated formula (ignore the fact that the formula returns a wrong value).
After you are done with the formula, delete the Today column from your list.
For some reason it works this way! Now Sharepoint treats the Today in your formula as today's date.
Note: If you decide you want to change the formula, you have to create the Today column again. Otherwise, it wouldn't recognize Today as a valid column.
I Tried #Farzad's approach and it seems to be working perfectly. I wanted to do a custom count on Days Elapsed so added a calculated column which previously I was using a difference between the Created Date and Modified Date Columns, which was only showing up whenever a user updated the post, much to my dismay.
I now have a formula which works as I would want to and uses the Today column, and here it is for anyone who would like to use it. I also have a Status column on the basis of which a base of On Hold is used, and the remaining formula are based on the date difference of Today - Created.
=IF(Status="On Hold","On Hold",IF(AND(Today=Created,(DATEDIF(Created,Today,"D")=0)),"New",IF(AND(Today<>Created,(DATEDIF(Created,Today,"D")=0)),"New (updated)",IF(DATEDIF(Created,Today,"d")>3,"Need Update Immediately",IF(DATEDIF(Created,Today,"d")=1,"One day old",IF(DATEDIF(Created,Today,"d")=2,"Two days old",""))))))
Basically its just a bunch of nested IF conditions which get me labels on the basis of which I can add a group to my view and filter out data if needed. Hope this helps anyone looking for an answer!

Resources