Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
fmazzarelli
Partner - Creator III
Partner - Creator III

YEAR / months

Hi,

i would create a variable dividing the year in 2 - 3 - 4 - 5 months.

a field "data" is colled DATE_ORD - YYYY/MM/GG

How could I do?

2 months:

gen - feb

mar - apr

mag - giu

lug - ago

set - ott

nov - dic

3 months:

gen - feb - mar

apr - mag - giu

lug - ago -set

ott - nov - dic

4 month

gen - feb - mar - apr

mag - giu  lug - ago

set - ott - nov - dic

6 months
gen - feb - mar - apr - mag - giu

lug - ago - set - ott - nov - dic

20 Replies
swuehl
MVP
MVP

Something like

LOAD *,

        Ceil( Month(DATE_ORD) / 2 ) As TwoMonthPeriod,

        Ceil( Month(DATE_ORD) / 3 ) As ThreeMonthPeriod,

        Ceil( Month(DATE_ORD) / 4 ) As FourMonthPeriod,

        Ceil( Month(DATE_ORD) / 6 ) As SixMonthPeriod;

LOAD Date#(DATE_ORD,'YYYY/MM/DD') as DATE_ORD

FROM YourTableSource;

fmazzarelli
Partner - Creator III
Partner - Creator III
Author

looking your code should be fine

I'm using it during reload data function. Is it correct?

Because "the command Ceil is a value unrecognized.

fmazzarelli
Partner - Creator III
Partner - Creator III
Author

ah, i'm using an sql table

swuehl
MVP
MVP

Is that the error you get when reloading?

ceil() is a numeric function and should work in a QV LOAD statement. Could you post your script or document log?

fmazzarelli
Partner - Creator III
Partner - Creator III
Author

select

campo1

,campo2

,campo3

from nomedatabase.[dbo].[nometabella]

swuehl
MVP
MVP

You need to use the QV functions in a preceding LOAD statement:

LOAD *,

        Ceil( Month(DATE_ORD) / 2 ) As TwoMonthPeriod,

        Ceil( Month(DATE_ORD) / 3 ) As ThreeMonthPeriod,

        Ceil( Month(DATE_ORD) / 4 ) As FourMonthPeriod,

        Ceil( Month(DATE_ORD) / 6 ) As SixMonthPeriod;

LOAD Date#(DATE_ORD,'YYYY/MM/DD') as DATE_ORD;

SQL SELECT ....

FROM YourTableSource;

fmazzarelli
Partner - Creator III
Partner - Creator III
Author

hi,

but the field DATE_ORD is extracted by a select (sql).

I tried to put them after but, i receive a syntax error (FROM is missing

SQL SELECT

[DATE_ORD]

FROM [DATABASE].[dbo].

;

LOAD *,

        Ceil( Month(DATE_ORD) / 2 ) As TwoMonthPeriod,

        Ceil( Month(DATE_ORD) / 3 ) As ThreeMonthPeriod,

        Ceil( Month(DATE_ORD) / 4 ) As FourMonthPeriod,

        Ceil( Month(DATE_ORD) / 6 ) As SixMonthPeriod;

LOAD Date#(DATE_ORD,'YYYY/MM/DD') as DATE_ORD;

swuehl
MVP
MVP

That's why a called it a preceding LOAD statement:

LOAD *,

        Ceil( Month(DATE_ORD) / 2 ) As TwoMonthPeriod,

        Ceil( Month(DATE_ORD) / 3 ) As ThreeMonthPeriod,

        Ceil( Month(DATE_ORD) / 4 ) As FourMonthPeriod,

        Ceil( Month(DATE_ORD) / 6 ) As SixMonthPeriod;

LOAD Date#(DATE_ORD,'YYYY/MM/DD') as DATE_ORD;

SQL SELECT

[DATE_ORD]

FROM [DATABASE].[dbo].

;

fmazzarelli
Partner - Creator III
Partner - Creator III
Author

OK

It works