Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Count weekdays

Hi all.

i want to create a table that lists for each weekday within a quarter how often this weekday occurs.

I want to start with the year 2008 and i want to doch this until 2015.

Example for 2008 (i did not check if the numbers make sense):

Quarter# of Mondays# of tuesdays# of Wednesdays# of thursdays# of Fridays# of Saturdays
# of Sundays
Q1-200820202020202121
Q2-200819191919191818
Q3-200821212121212020
Q4-200820202020202020








Thanks a lot!

1 Solution

Accepted Solutions
CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     Do you have a Master calendar?

     If not create like this.

Calendar:

Load

          Date(Date#('1/1/2008','D/M/YYYY')+RowNo()-1) as Date,

          QuarterName(Date#('1/1/2008','D/M/YYYY')+RowNo()-1) as Quarter,

          WeekDay(Date#('1/1/2008','D/M/YYYY')+RowNo()-1) as WeekDay

AutoGenerate

          Interval(Date#('31/12/2015','D/M/YYYY')-Date#('1/1/2008','D/M/YYYY'),'D');

NumberOfDays:

Load

          Quarter,

          Count('*') as Monday

Resident Calendar where WeekDay=0

Group By Quarter;

Left join

Load

          Quarter,

          Count('*') as Tuesday

Resident Calendar where WeekDay=1

Group By Quarter;

Left join

Load

          Quarter,

          Count('*') as Wedesday

Resident Calendar where WeekDay=2

Group By Quarter;

Left join

Load

          Quarter,

          Count('*') as Thursday

Resident Calendar where WeekDay=3

Group By Quarter;

Left join

Load

          Quarter,

          Count('*') as Friday

Resident Calendar where WeekDay=4

Group By Quarter;

Left join

Load

          Quarter,

          Count('*') as Saturday

Resident Calendar where WeekDay=5

Group By Quarter;

Left join

Load

          Quarter,

          Count('*') as Sunday

Resident Calendar where WeekDay=6

Group By Quarter;

Celambarasan

View solution in original post

8 Replies
CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     You mean number of mondays occur in that quarter like that?

Celambarasan

Not applicable
Author

Please create a standard calendar table

with YearQuarter and Weekday in it

All you need to Pivot on these values and do the count

Regards

Kulbir

Not applicable
Author

Yes, exactly. I want to know f.e. the number of Mondays in a quarter..

jagan
Luminary Alumni
Luminary Alumni

Hi,

In Load script, get the Day as separate column

LOAD

     WeekDay(Day) AS Day,

    '

     '

     '

FROM DataSource;

Now in straight table

Use Quarter as dimension

And use expressions like

# of Mondays =Count({<Day={'Mon'}>} Day)

# of Tuesdays =Count({<Day={'Tue'}>} Day)

'

'

'

# of Sundays =Count({<Day={'Sun'}>} Day)

Or

Just drag the Day dimension horizontally and use

Count(Day)

Hope this helps you.

Regards,

Jagan.

perumal_41
Partner - Specialist II
Partner - Specialist II

Hi

Try This Expression

  =Count({<Datefiled={'>=$(=min(DateFiled))<=$(=max(DateFiled))'}>}weekday(Datefiled))

Regards

Perumal

Not applicable
Author

Thanks for all the ideas and replies, but: i want to do this in the LOAD script only.

Any thoughts ?

Thanks a lot!

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try this

TempTable:

LOAD

     WeekDay(Day) AS Day,

    '

     '

     '

FROM DataSource;

LOAD

     Quarter,

     Day,

     Count(Day) AS Count

RESIDENT TempTable

Group By Quarter,Day;

Regards,

Jagan.

CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     Do you have a Master calendar?

     If not create like this.

Calendar:

Load

          Date(Date#('1/1/2008','D/M/YYYY')+RowNo()-1) as Date,

          QuarterName(Date#('1/1/2008','D/M/YYYY')+RowNo()-1) as Quarter,

          WeekDay(Date#('1/1/2008','D/M/YYYY')+RowNo()-1) as WeekDay

AutoGenerate

          Interval(Date#('31/12/2015','D/M/YYYY')-Date#('1/1/2008','D/M/YYYY'),'D');

NumberOfDays:

Load

          Quarter,

          Count('*') as Monday

Resident Calendar where WeekDay=0

Group By Quarter;

Left join

Load

          Quarter,

          Count('*') as Tuesday

Resident Calendar where WeekDay=1

Group By Quarter;

Left join

Load

          Quarter,

          Count('*') as Wedesday

Resident Calendar where WeekDay=2

Group By Quarter;

Left join

Load

          Quarter,

          Count('*') as Thursday

Resident Calendar where WeekDay=3

Group By Quarter;

Left join

Load

          Quarter,

          Count('*') as Friday

Resident Calendar where WeekDay=4

Group By Quarter;

Left join

Load

          Quarter,

          Count('*') as Saturday

Resident Calendar where WeekDay=5

Group By Quarter;

Left join

Load

          Quarter,

          Count('*') as Sunday

Resident Calendar where WeekDay=6

Group By Quarter;

Celambarasan