Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Semi Anually

Posted on 2011-03-02
8
Medium Priority
?
441 Views
Last Modified: 2012-05-11
I have data that I would like to group semi anually:

from year 2011-2016

I created corsstab query but there is no option for semi anuallay.

Expr1: "Qtr " & Format([Date],"q")

Suggestions?
Thanks
0
Comment
Question by:HappyAlways
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 10

Expert Comment

by:Michael Vasilevsky
ID: 35021594
By semi-annually you mean quarterly? Use DatePart

Expr1: DatePart("q",Date())
0
 

Author Comment

by:HappyAlways
ID: 35021683
No, every six month

if we start from april then it will add the numbers from April to September
0
 
LVL 58
ID: 35021695
<<I created corsstab query but there is no option for semi anuallay.>>

  You'd have to write a function to return that.  And by semi-annual, I'm assuming you mean two periods in a year; dates before 6/30 and those falling after.

JimD.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 52

Expert Comment

by:Gustav Brock
ID: 35021873
You may use (group by) this function - or just the core of it:
Public Function Semiyear( _
  ByVal datDate As Date) _
  As Integer

' Returns 1 if datDate falls in first semiyear of the year of datDate.
' Returns 2 if datDate falls in second semiyear of the year of datDate.

' 2007-01-06. Cactus Data ApS, CPH.

  Const cintMonthsPerSemiyear As Integer = 6
  
  Dim intSemiyear             As Integer
  
  ' No specific error handling.
  On Error Resume Next
  
  intSemiyear = -Int(-Month(datDate) / cintMonthsPerSemiyear)
  
  Semiyear = intSemiyear
  
End Function

Open in new window

/gustav
0
 
LVL 3

Accepted Solution

by:
JAMcDo earned 2000 total points
ID: 35023653
Focusing on your clarification:

        "No, every six month

         if we start from april then it will add the numbers from April to September ",

Does this function do what you want?

Public Function SixMonthGroup(datDate As Date) As Integer

    'There aren't any limits on the [datDate] processed.
    'Eg.  If [datDate] < Now(), a zero or negative may be the result
   
    Dim MDiff As Integer
   
    MDiff = DateDiff("m", Now(), datDate)

    SixMonthGroup = Int(MDiff / 6) + 1
   
End Function

J.
0
 

Author Comment

by:HappyAlways
ID: 35023663
The data starts from April 2011 and end 2016. I want to run the report so I can group the data semi anually. I did it the simple way which I grouped the date quarterly then I added every two quarter together to get every 6 months.
0
 
LVL 3

Expert Comment

by:JAMcDo
ID: 35023755
Let me try again . . .

My first attempt only counts the 'Month' part without regard to the day of the month.  I am assuming that you want the six periods to be grouped starting from Now() - the current date.  If you want to start at a specific date, replace Now() with the date.  eg.  #01 Apr 2011#


Public Function SixMonthGroup(datDate As Date) As Integer

    'There aren't any limits on the [datDate] processed.
    'Eg.  If [datDate] < Now(), a zero or negative may be the result
   
    Dim MDiff As Integer
   
    MDiff = DateDiff("m", Now(), datDate) - IIf(DatePart("d", datDate) < DatePart("d", Now()), 1, 0)

    SixMonthGroup = Int(MDiff / 6) + 1
   
End Function

This returns a group values for dates greater than Now().

If Now() = #02 Mar 2011#

The first 6 months returns a 1 (#02 Mar 2011# to #01 Sep 2011#)
 the next 6 months returns a 2,  (#02 Sep 2011# to #01 Mar 2012#)
the third range of 6 months returns a 3  (#02 Mar 2012# to #01 Sep 2012#)
etc.

Then you can use the SixMonthGroup number to group the records.

J.
0
 
LVL 3

Expert Comment

by:JAMcDo
ID: 35023817
A 3rd try . . ., now that I better understand what you want (I think)

Does this do it?

Public Function SixMonthGroup(datDate As Date) As Integer

    'There aren't any limits on the [datDate] processed.
    'Eg.  If [datDate] < #01 Apr 2011#, a zero or negative may be the result
   
    Dim MDiff As Integer
    Dim SDate As Date
   
    SDate = #4/1/2011#
   
    MDiff = DateDiff("q", SDate, datDate)

    SixMonthGroup = Int(MDiff / 2) + 1
   
End Function

J.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question