Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
JustinDallas
Specialist III
Specialist III

Count # of Weeks in Period

Hello Folks,

I am attempting to count the number of weeks in a period/month.  There is some logic to what a "Period" is so I can't use too many built-in and conventional methods.

Right now, when I run my script I'm left with this

BadPeriods.png

 

Whereas I want something similar to the numbers in Red.  Here is my script below, I'm confused why the LOAD COUNT("...") GROUP BY ... is giving me the number of DAYS in the period.

 

//[BEGIN SCRIPT]

LET vStartYear = 2019
;
LET vEndYear = 2022
;
LET vStartDate = Date(YearStart(MakeDate(Year(Today())-2)))
;
LET vEndDate = Date(YearStart(MakeDate(Year(Today())+2)))
;
TRACE 'Start date: $(vStartDate), End date: $(vEndDate)'
;

DATA:
LOAD *,
Floor(Num("Period Year")) & '/' & Floor(Num("Period")) as '%budget_period_key'
;
LOAD
Date('$(vStartDate)' + IterNo()) AS "Date",
DayStart(WeekEnd(Date('$(vStartDate)' + IterNo())) - 6) AS "Period WeekStart",
DayStart(WeekEnd(Date('$(vStartDate)' + IterNo()))) AS "Period WeekEnd",
Year(WeekEnd(Date('$(vStartDate)' + IterNo()))) AS "Period Year",
Num(Month(WeekEnd(Date('$(vStartDate)' + IterNo())))) AS "Period"
AutoGenerate 1
While '$(vStartDate)' + IterNo() <= '$(vEndDate)'
;

Blah3:
LOAD Count(DayStart(Floor(Num("Period WeekStart")))) AS 'Weeks In Period', %budget_period_key
RESIDENT DATA
GROUP BY %budget_period_key
;
Loosen Table Blah3
;

EXIT Script
;

//[END Script]

Labels (4)
1 Solution

Accepted Solutions
JustinDallas
Specialist III
Specialist III
Author

I didn't have DISTINCT in the Count field.  I assumed that the Distinct wasn't necessary because the syntax highlighter left it black as opposed to turning it blue like it does other keywords.

 

DISTINCT.png

View solution in original post

1 Reply
JustinDallas
Specialist III
Specialist III
Author

I didn't have DISTINCT in the Count field.  I assumed that the Distinct wasn't necessary because the syntax highlighter left it black as opposed to turning it blue like it does other keywords.

 

DISTINCT.png