Results 1 to 4 of 4

Thread: [RESOLVED] Calculate Fields in Domain Aggregate Functions using DateDiff

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2010
    Posts
    34

    Resolved [RESOLVED] Calculate Fields in Domain Aggregate Functions using DateDiff

    I have a table tblDocInfo which I made a continuous form with the fields
    PurchaseOrderApprovalDate and ActualDeliveryDate and primary key docID (autonumber). I have a calculated control difTargetOutputStep1 with Control Source=DateDiff("d",[PurchaseOrderApprovalDate],[ActualDeliveryDate])

    I want to calculate the average of these values on the form (will be all values ActualDeliveryDate-PurchaseOrderApprovalDate for the tblDocInfo).

    In summary: I have a field showing the number of days between the ActualDeliveryDate and PurchaseOrderApprovalDate. I would like the user to be able to compare this value for each docID to the average of all of the days between the ActualDeliveryDate and PurchaseOrderApprovalDate.

    For some reason I am having a hard time with this....any suggestions?

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Calculate Fields in Domain Aggregate Functions using DateDiff

    I am not sure if there is a shorter way of doing this but this logic is what I could think of at the moment...

    1) Declare an Array. The size of the array will be the tables record count.
    2) Loop through each record and find ActualDeliveryDate-PurchaseOrderApprovalDate and store it in the above array.
    3) Find Average using the values stored in the array.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Calculate Fields in Domain Aggregate Functions using DateDiff

    On Form Header or Footer, create a control TextBox with ControlSource as:
    =Avg([ActualDeliveryDate]-[PurchaseOrderApprovalDate])
    or
    =Avg(DateDiff("d",[PurchaseOrderApprovalDate],[ActualDeliveryDate]))
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2010
    Posts
    34

    Re: Calculate Fields in Domain Aggregate Functions using DateDiff

    Thank you! I was using DAvg and it was giving me an error #Name?. ugh.... Thanks again.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width