Find difference in days between two date fields in Infopath - infopath

Could someone help me with determining the difference in days between two date fields in InfoPath forms.
Usual subtraction doesn't work with the date fields. like DateField1 - DateField2. Any code or no code solution is highly appreciated.

There are ways to get difference of dates in InfoPath, but they are very complex and involve writing rules and parsing the date into month/day/year. Instead, I recommend this method described elsewhere that uses Excel Services. Because Excel is excellent at calculations, it makes sense to write the calculations in Excel and call the Excel document from InfoPath (if you have SharePoint with Excel Services).
Here are 2 sets of instructions on how to set up InfoPath and Excel Services. The instructions are long and/or copyrighted so I cannot include them here, but to summarize you would set up new Data Connections in InfoPath to use web services (SOAP) open the Excel document and set the date fields based on your InfoPath date fields and retrieve the calculated value from Excel.
Calculating date differences in InfoPath using SharePoint Excel Services
InfoPath and Excel Services
It took me about an hour to get it working because I had to do some trial & error with the Trusted Location settings.

I utilize a separate SharePoint list to help calculate the number of days between two dates in Infopath. This is so I can account for leap years and have the ability to just count work days, not all days. I update this list with new data once a year.
Here is the Excel file source for the list containing 2018-2020 data: https://1drv.ms/x/s!ApLhBloaS1wVgsUOMRrRfbekFftY9Q
Steps:
Import the first worksheet of the above Excel file as a new list in Sharepoint.
Add a receive data connection to this list from your InfoPath form.
For the first date, create a action to convert the date to a number in YYYYMMDD format. Assuming the date is stored as DateTime, you can use this formula:
floor(number(translate(substring-before(../my:endDate, "T"), "-", "")))
Query the list for the number value of the first date. Store this number in a field (column) in your form. (This field does not need to show in your form.)
Repeat steps 3 & 4for the second date.
Subtract the first date number from the 2nd, store this in a third column.
Note: The Excel file uses the formula "NETWORKDAYS" and includes columns for weekdays, weekdays minus US Federal holidays, and weekdays minus NYSE holidays. Now you can get the number of work days between two dates using one of these columns. If you live outside the US, you could add a column to the Excel for other holidays, such as UK bank holidays.

Related

IMPORTHTML / Table Pull Issues [duplicate]

This question already has answers here:
Scraping data to Google Sheets from a website that uses JavaScript
(2 answers)
Closed last month.
Trying to import weather forecasts for multiple sales markets, but the site I was using blocked Bot Crawl, so my ImportHTML function can't fetch the URL.
I found another site, but the table is formatted in calendar view instead of the list view.
Can I still pull this information into Google Sheets (GS) somehow? I've gotten it to pull information, but it just comes up as [TABLE] in GS.
This is the code I was using to pull changing dates:
=CONCATENATE("https://www.wunderground.com/calendar/us/ca/eureka/KACV/date/",$B$3,"-",$C$3,"?cm_ven=localwx_calendar")
And the code to pull the completed URL's table into GS:
=IMPORTHTML(A2, "Table", 1)
I want the first string of code to pull today's year and month from B3 and C3, and Concatenate, and then the second string of code pulls all that together and then pulls the desired table from the website, but I get a bunch of cells with [TABLE].
There is an API that returns json. Look into documentation to see if there is an endpoint that meets your needs. For example, network tab shows the following for 15 day forecast
https://api.weather.com/v3/wx/forecast/daily/15day?language=en-US&apiKey=6532d6454b8aa370768e63d6ba5a832e&geocode=40.95%2C-124.11&units=e&format=json
You would probably need to write your own script to handle this response though or use a tool like ImportJSON. With a little research it is highly likely you will find something suitable.
Explore 15 day forecast JSON here

Dimensional Date Table with multiple first day of weeks

I am about to start creating a dimensional date table for a Data Warehouse project using SQl Server 2012.
On of the first user comments is that....
'Different customers will have a different first day of week, so not always a Monday'.
How would I accomodate for potentially 7 different start of week days in a single dim table or should i simply calculate it the conventional way on the fly on a per customer basis in a fact table and not use the dim date table?
Option 1. Calculate it on the fly using built in date match functions. SQL Server defaults to Sunday as the first day of the week.
Option 2. Create an additional column in your table for each day of the week indicating its day number of the week. For example column TuesdayFirst would have a 1 for every Tuesday and a 2 for each Wednesday.
Option 3. (Best) Create a view on your date dimension that calculates the additional columns for each day. Any of the columns that are not needed in the select will be ignored and not calculated. This gives the benefits of the persistent columns and the consistent calculation method, but does have some processing overhead versus pre-calculating.
If you choose option 3, do not use a CASE statement to calculate it. You must do it strictly with date math in order for it to perform decently when aggregating.

Repartitioning Google Analytics data based on publish date

I'm looking to repartition Google analytics data from stats date tables (the default export we get each day) to dated tables based on published date of each article URL (a custom dim we have). This is for more efficient querying by publish date by a BI dashboard that needs to calculate user counts on the fly for arbitrary date ranges.
So plan is to append data each day to the relevant publish dated tables. Just wondering if there is an easy way to do this or if I need to look though each stats date data for all the publish dates that had hits each day and then append one by one to relevant publish date tables?

Infopath 2010 How to get the total of fields with a Time Data Type in a repeating table

Please help... I am noob to Infopath coding and I am having a hard time with finishing a project. I have setup a repeating table where it should count the time spent for each activity. Below is the screenshot
I want to be able to get the total time for the column "Activity Time" and place it on the Footer of the repeating table. I already tried Googling for some answers but can't find one for a Time Data Type.
Thank you in advance.
Infopath cannot add time values into a total like that. You need to convert the time values into numbers, then sum the numbers and convert the result back into a time value.
Step by step instructions are on the InfoPath blog from Microsoft here:
http://blogs.msdn.com/b/infopath/archive/2007/02/21/calculating-elapsed-time-without-code.aspx

Freezing Previous Years Data

I have a database that tracks employee’s data for the current year and previous years.
In examples below I will use calendar years (years start in Jan and end in Dec)- this is not always the case, some users have their year running from July to June- or April to March, etc.
There are many tables that, with a few heavy calculations, make a view of the employee’s data at this point in time.
This current year’s data is what users look at mostly. But data from previous years impact on this year (so, a change made to the 2008 data- will have a knock on effect on 2009, and then into 2010 and so onto this year).
Obviously, this has a negative impact on performance when viewing reports as viewing this year’s data will mean trudging through all the previous years- calculating and creating views until the end result is found. As the application ages, this problem will get worse and worse- say in 2015, anybody using the system from its inception (2008) will be waiting for a long time to get their data.
We plan to freeze previous years data so instead of having data from 2008, 2009, 2010 and this year’s data- we would have one block with the previous year’s data (with all calculations done for those previous years) and this year’s data.
In this way, we would have the end results data for all the previous year’s already calculated and we would only need to add to this year to get the final result.
Obviously, we would have to prevent users from entering/updating data in previous years.
My question is what is the best way to achieve this? I presume you would need some process that waits until the new year and does some calculations.
Thanks in advance,
ViperMAN.
the approach you describe is normally referred as data archiving, you can have some queries a DBA runs manually every year the first working day after the new year party so the calculated data is prepared and stored.
Also, your application needs to deny users to modify previous years data, if I have got it right.
One approach I was thinking works as follows:
Create a table that holds the result of the previous years calculations.
Prevent all addtions/deletions/updates to previous years from the app tier.
Change reporting so that queries would consult this table instead of trudging along, calculating everything out each time.
Have a daily process that would:
Check if today was the first day of an employees year-
If yes, get all of the elapsed year's data and add them to all the previous years.
Obviously, this is a simlified version- but one that I think could work.
Thoughts?
If you have data that should not be edited, and you can define what that data is, then I would use a combination of stored procedures and security settings to ensure the old data stays accurate.
If you used stored procedures as a filter, you can have logic in your stored procedure that checks the record against the current DateTime and only allows the update if everything fits your requirements.

Resources