Count function within date/time

Using Crystal Reports X, I need to calculate how many people are in a building at any given hour over rolling 24 hour periods. Each person entering is recorded by dd/mm/yyyy hh:mm:ss and the same method is used when they leave thus each person has a time span in the building. I know the date/time of leaving is critical to this in terms of whether it's populated or is null but I'm getting caught on the calculation in between. The two date/time fields should allow their presence in the building to be recorded and counted each hour. The critical point will come at midnight where the DateDiff function will need to apply. Does anyone have a solution that doesn't involve multiple formulae or stored procedures?

Assuming your base data is some sort of log, with one record for an entry and one for an exit, this is really quite simple.  No DateDiff needed! 
Pull all of the logs for the time frame that you want to report, then keep track of the ins and outs with a formula something like (basic syntax):
global inBuilding as number
if {table.action} = "IN" then
  inBuilding = inBuilding + 1
else
  inBuilding = inBuilding - 1  ' assuming action is only IN or OUT
end if
formula = ''
Place this on the detail format.  Group your records by hour, and on the group footer, place this:
global inBuilding as number
formula = inBuilding
Which will show the number of people in the building at the end of that hour.
There are two issues with this, both of which can be gotten around:
1) The number of people in the building at the start of the reporting period is not taken into account.  For that, you might want to create a summary table by hour (a datetime; or at midnight by date) and the number of people in the building, then add that into your data.  (Or you could go through all of the records from the beginning of time, but in a few years, that'll be really, really slow!)
2)  It does not necessarily show every hour of every day (if there are no log entries for the hour).  In order to do that, you'd need to have a "master calendar" type table that does have every hour of every day (don't forget about Daylight Savings Time!) and use that on the left side of an Left outer Join to your other data.
HTH,
Carl

Similar Messages

  • Count Function on Date Field in Discoverer

    Hey folks,
    How would someone like to educate a novice on how to perform a count function on a date field? I am writing a Discoverer report and have a requirement to display counts of the number of records that have a modified date of > 30 days and > 60 days. I am trying to use the 2nd count function as such: COUNT(modified_date < (SYSDATE - 30)). I keep getting the "error in function" message. I have tried it with CURRENT_DATE as well and get the same error.
    Any help would be greatly appreciated.
    Thanks much,
    Schuyler

    Hi
    You can't use logical expression in a function like this:
    COUNT(modified_date < (SYSDATE - 30))
    instead of this use CASE expression:
    COUNT(case when modified_date < (SYSDATE - 30) then 1 else 0 end)
    Ott Karesz
    http://www.trendo-kft.hu

  • Convert labview date/time to excel date/time

    How do I convert the "seconds since 1904" from the function "Get Date/Time in Seconds" to an MS Excel date/time format? The application runs in the Solaris environment.

    hi, I am not sure about Solaris env.
    Maybe this will help in one way or another.
    Regards
    ian.f
    Sg/My
    Ian F
    Since LabVIEW 5.1... 7.1.1... 2009, 2010
    依恩与LabVIEW
    LVVILIB.blogspot.com
    Attachments:
    GetDatenTime_to_File.vi ‏48 KB

  • The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart.

    The below function is giving me the hours difference what I wanted, but today it is giving us the below error: 
    Msg 535, Level 16, State 0, Line 1
    The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart.
    Please Help..
    ALTER FUNCTION [dbo].[GetHoursExcludingWeekdays](@StartDate datetime2,@EndDate datetime2)
    returns decimal(12,3)
    as
    begin
        if datepart(weekday,@StartDate) = 1
            set @StartDate = dateadd(day,datediff(day,0,@StartDate),1)
        if datepart(weekday,@StartDate) = 7
            set @StartDate = dateadd(day,datediff(day,0,@StartDate),2)
        -- if @EndDate happens on the weekend, set to previous Saturday 12AM
        -- to count all of Friday's hours
        if datepart(weekday,@EndDate) = 1
            set @EndDate = dateadd(day,datediff(day,0,@EndDate),-2)
        if datepart(weekday,@EndDate) = 7
            set @EndDate = dateadd(day,datediff(day,0,@EndDate),-1)
        declare @return decimal(12,3)
        set @return = ((datediff(second,@StartDate,@EndDate)/60.0/60.0) - (datediff(week,@StartDate,@EndDate)*48))
        return @return
    end
    ReportingServices

    You'll get this error if the difference between the start and end date is greater that about 68 years due to the "second" DATEDIFF specification.  Perhaps the dates are greater than the expected range due to a data quality issue. 
    Taking the advice from the error message, you could use minutes instead of seconds like the example below the version below.  This could still result in the error of the difference is greater than a couple of hundred years, though.  You might consider
    validating the dates and returning NULL if outside expected limits.
    ALTER FUNCTION [dbo].[GetHoursExcludingWeekdays](@StartDate datetime2,@EndDate datetime2)
    returns decimal(12,3)
    as
    begin
    if datepart(weekday,@StartDate) = 1
    set @StartDate = dateadd(day,datediff(day,0,@StartDate),1)
    if datepart(weekday,@StartDate) = 7
    set @StartDate = dateadd(day,datediff(day,0,@StartDate),2)
    -- if @EndDate happens on the weekend, set to previous Saturday 12AM
    -- to count all of Friday's hours
    if datepart(weekday,@EndDate) = 1
    set @EndDate = dateadd(day,datediff(day,0,@EndDate),-2)
    if datepart(weekday,@EndDate) = 7
    set @EndDate = dateadd(day,datediff(day,0,@EndDate),-1)
    declare @return decimal(12,3)
    set @return = ((datediff(minute,@StartDate,@EndDate)/60.0) - (datediff(week,@StartDate,@EndDate)*48))
    return @return
    end
    GO
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • ITunes 11 no longer updates the song play count or the last played date/time on Win7 and on Macs

    I've downloaded and installed iTunes 11 on 2 Win7 PC's, on my Macbook (Mountain Lion), MacbookPro (Snow Leopard) and new Mac mini (Mountain Lion). The song "play count" and "last played date/time" do not update after playing songs on any platform. This problem needs to be corrected as I have 2 iPods and an iPhone that I like to sync every few days. I have not tried the sync yet and will not as long as this problem persists.

    I read another similar post about this same issue, where it was said the the "next play" list could be cleared to get the play count and last played date/time to update. That is true, however iTunes stops playing from the playlist entirely - all you hear is the single song. This is not any sort of upgrade or fix. For the sake of one nicety, Apple programmers have broken a fundamental feature and function. This is not good!

  • Distinct count on date/time field...

    Hi,
    I am trying to a distinct count on this formula that takes a date/time field and converts it to a date in order to get a distinct count of dates.  However, it's not working... say, if I have two dates are the same (the times may be different), it's counted twice.  Any suggestions?  I tried to convert this to a string thinking the evaluation may change, but no dice.  Thanks!!
    if not isnull({AVAILABILITY.PAT_ENC_CSN_ID}) then
        cstr(cdate({AVAILABILITY.SLOT_BEGIN_TIME}))
    else

    You can use the following formula...
    DateAdd("d", DateDiff("d", #1/1/1900#, {TableName.YourDateTimeField}), #1/1/1900#)
    This will set each date value to 12:00 am of it's respective day...
    So 8/16/2010   3:01:20PM would become 8/16/2010  12:00:00AM
    Now you can group on this formula field and then simply do a count on the date at the appropriate group level.
    HTH,
    Jason

  • "Date/Time To Seconds" Function does not respond to "fractiona​l second" input

    The "Date/Time To Seconds" function (contained in the Fuctions\Programming\Timing - Palette) does not respond to the "fractional second" input (see attached example).
    Reimar Spohr
    Attachments:
    Date-Time To Seconds VI Example.png ‏18 KB

    Instead of creating a new post, you should have posted this in the original thread, where people already tried to help you. Please keep the discussion in that thread.

  • Function Module to Compare Date within date Range

    Hi All,
            Does anyone know Function Module to Compare Date within date Range...For example i need to find whether 08/02/2006 falls in between 07/15/2006 and 09/15/2006......

    data: datum type sy-datum value '20070802',
          datum_low type sy-datum  value '20070730',
          datum_high type sy-datum value '20070930'.
    If datum between datum_low and datum_high.
    Endif.
    Regards,
    Rich Heilman

  • FUNCTION MODULE TO CONVERT DATE / TIME INTO WORDS.

    HI EXPERTS,
         FUNCTION MODULE TO CONVERT DATE / TIME INTO WORDS.
    PLS DO HELP.....

    Hiii gita
    we have another FM SPELL_AMOUNT
    regards
    Jaipal

  • FUNCTION Variable within Data Template

    Hi Im calling a function within my sql and i want to use the result as a bind variable.... here goes...
    Data Template...... XML
    <sqlStatement name="Q1">
    <![CDATA[select function_name(ppp.id) the_main_one,
    :the_main_one + 10 new_value
    from per_ppp]]>
    </sqlStatement>
    I get null value .... but from the_main_one i get a value..... any ideas... i checked for number and nvl(,0) and all that no luck
    is there a grouping thing involved here... where as i need to call the function from within another sql statement...

    It can be done.
    Step 1: Setup package.
    Step 2: Create a global variable for your function value
    Step 3: Before the calling function returns the value, set a global variable (placeholder)
    Step 4: Create a new function that returns the global variable, make sure it's after the first function call. Returning the value you might want to reset the global variable to null....
    Your good to go.
    Ike Wiggins
    http://bipublisher.blogspot.com

  • Function module to segregate date time

    Hello,
    I have a field in the table which stores the date time as one whole value: 17.06.2010 16:48:51.
    the data type for this field is DEC 15.
    I need a FM which can segregate the date and time from this field values. I want date and time as separate values.
    there must be some standard FM to do this.
    any help?
    Thanks & regards,
    Ravish

    Don't know whether this question should be answered or not.
    Mods if you find it wrong , then exercise your right and lock it.
    @op - use fm CACS_TIMESTAMP_GET_DATE

  • Power Query Language Functions to Convert a UTC Date/Time to MST

    I need to convert an implicit UTC date/time value to a MST date/time value.  I thought that I could achieve this by converting to an ISO 8601 compliant text representation of the MST date/time value (see below) and then back to a date/time value, but
    it's not working ...
    DateTime.FromText( DateTime.ToText( [MIN_REVSN_RLSE_DTTM] ,"yyyy-MM-ddThh:mm:ss-07")) 
    Is this a bug?  Or, is there a better way to do this?

    That's a fixed duration. Why not just [MIN_REVSN_RLSE_DTTM] + #duration(0, -7, 0, 0)?
    EDIT: For what it's worth, I don't think PQ ever does anything with DST anyway. This has both good points and bad points.

  • In "find my iPhone" i entered the functional "delete data". now i found my iPhone. it was not online. How can i modify it? nothing is deleted at this time

    in "find my iPhone" i entered the functional "delete data". now i found my iPhone. it was not online. How can i modify it? nothing is deleted at this time

    If you selected to erase the device using the find my iPhone erase feature, as soon as your iPhone reconnects with apple systems, it will erase.  This command cannot be cancelled.  However, you will be able to restore your device using the most recent icloud or itunes backup.
    Hope this helps.

  • Sql count function in order by clause

    Post Author: krypton
    CA Forum: Data Connectivity and SQL
    Hi Guys
    Can i ask a quick question. I am trying to retrieve data remotely from a SQL Server via crystal reports.
    Within the Database Expert I have entered a SQL query to retrive the number of (call center) support calls raised by our customers:-
    Select `Primary_Company`, COUNT(`Calls`)From  `SPRT_Issue` GROUP BY  `Primary_Company`ORDER BY  COUNT(`Calls`) desc
    The customer's column is called 'Primary Company' and the calls they raise are in the 'Calls' column. the above is a normal sql query.
    However Crystal fails to run the query and generates an error message :-
    Failed to open a rowset. Details: 420: Driver&#93; Expected lexical element not found: <identifier>
    I dont understand why it wont run. In the ORDER BY clause if i replace field 'Calls' by the field 'Primary Company' then it works.
    I think the problem is that it wont accept the count function in the order by clause. which is what i want it to do i.e display the calls in descending order by each customer.
    Could someone tell me if there is a way around it.
    Thanks
    Krypton

    Post Author: krypton
    CA Forum: Data Connectivity and SQL
    Thanks Lynn
    I tried your suggestion. But there is one probelm.
    When i sort the data in descending order using the count(calls) field, the data is returned but the customer's name appears multiple times along with their calls raised.
    E.g, if customer Mark raised multiple calls i.e. 2, 5, and 10 calls, then the report will show
    Mark   2
    Mark  5
    Mark 10
    But is there a way to aggregate all the calls for mark and show them only once:
    such as Mark   17
    Thanks

  • Distinct Count Function-how to use properly

    Hello,
    I am new to using forums & have only been using Crystal since May of 2009, so i hope i do this correctly & provide the appropriate information.  i've looked for this answer in what's been posted but cannot find it.  Some things i've read I don't really understand.  I only know how to use the functions that are in the software, i don't know how to write them myself (i think that's when people have referred to SQL code or basic syntax)
    I have CR Professional, version 11.0.0.1282 (Crystal Reports XI).
    I work at a county health dept and we have a annual medicaid cost report,  I am linking Crystal to our EMR billing module.  i have my report sorted by insurance, ie medicaid, bcbs, abw, hpm etc.  and within each ins group i have the clients ID, DOS (date of service), procedure code, charge amt, ins pmt & patient pmt.  i have totaled the charges & pmts for each group-works fine.  i even have been able to create the formula to adj out the duplicate entries in the billing module (a service was entered wrong then adjusted out then re-entered correctly-without my formula crystal was pulling both these records and adding them to total charges.)
    Where my problem lies and what my question is:  I need to count encounters, an encounter is the visit, but each visit could have 2 or more procedure codes.   So this results in multiple lines on my report for one visit, which i want for the charges to add correctly, but it makes my visit count to high. So I read about the distinct count function, of which there are three listed & i'm having a hard time understanding the differences.  What i tried is: a distinct count of the acct ID-so the same acct ID's are only counted the one time.  But some clients see us more than once per year, meaning the acct ID is the same but the DOS is different.  For this client that would be 2 visits.  But crystal is counting this as 1.
    Saying what i want to do is this:  Count as 1 when the acct ID and DOS are the same.  I've tried using the different distinct counts but when i check my formula it always has errors.  So I'm sure my lack of knowledge is what's holding me up-i fully believe crystal can do this.
    Any help would be greatly appreciated.

    I create a dummy table, set up acc_id and DOS and Charge.
    Created a running total
    Summarized acc_id
    Type of summary Count
    Evaluated using a formula
         <> previous ()
    and reset on ACC_ID
    My groups were sorted by acc_id and date
    where there were multiple visits on the same DOS my count was 0
    where the dos changed it would count accordingly.
    You may need to use two Running totals to get the complete picture.

Maybe you are looking for

  • Partner profile not available.

    Dear Folks, i am doing the scenario JDBC to IDOC. For that i did all the necessary ALE settings and configured the systems. While executing that scenario. In we02, i am getting the error partner profile not available eventhough i configured it. From

  • Going from PSE 9 to PSE 12

    We are currently running PSE 9 and want to install and update to PSE 12.  Are there any special install instructions?  Do we need to I install PSE 9 before installing PSE 12?  Will all our PSE 9 libraries be saved when we install PSE 12? Thanks

  • Inter company payments

    Hi experts, How to make intercompany payments through F110? what is the customization needs this? and how to give the inputs in the APP? points assured Soma

  • Need help with REX queries

    Can anyone help explain behavior in the OER Extensibility Framework/REX openapi that I am seeing. I may have misunderstood the documentation and I admit I'm looking at the 11g version of the api online and using it against 10.3 Anyway I'm trying to f

  • Adding mailbox to E63

    Dear All, When I use my SD card for "memory in use" (Messaging/Settings/Other/Memory in Use), I cannot seem to add hotmail (in Messaging/Options/Settings/E-mail) as a second mailbox (the default is gmail). I just end up with a message saying a bookma