Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

creating a period 'yyyy-mm' from a date field

I would like to have a field which shows the year then month of the transaction as a field selected in my reports. I've highlighted my attempt to create the field. Can someone please advise me what I have done wrong?

LOAD

  `st_account` as %Key.Customer,

  `st_account`,

    `st_trdate`,

     date(date#(`st_trdate`, 'dd-mm-yyyy'),'yyyy-mm') as Period,

    `st_trref` AS %Key.Trans,

    `st_custref`,

    `st_trtype`,

    `st_trvalue`,

    `st_vatval`,

    `st_trbal`,

    `st_paid`,

    `st_crdate`,

    `st_advance`,

    `st_payflag`,

    `st_dueday`,

    `st_type`,

    `st_delacc`,

    id,

    `st_pedate`;

SQL SELECT `st_account`,

    `st_trdate`,

    `st_trref`,

    `st_custref`,

    `st_trtype`,

    `st_trvalue`,

    `st_vatval`,

    `st_trbal`,

    `st_paid`,

    `st_crdate`,

    `st_advance`,

    `st_payflag`,

    `st_dueday`,

    `st_type`,

    `st_delacc`,

    id,

    `st_pedate`

FROM stran;

1 Solution

Accepted Solutions
muthukumar77
Partner - Creator III
Partner - Creator III

May be like this,

Date(Floor(st_trdate),'YYYY-MM')

Muthukumar Pandiyan

View solution in original post

9 Replies
vishsaggi
Champion III
Champion III

What is the format for `st_trdate' field coming from your Database?

Not applicable
Author

guess

Date(st_trdate,'YYYY-MM') as Period

should be fine.

What is the error you are getting?

Thank you!

Anil_Babu_Samineni

May be using Preceding Load. Try with these 3 conditions

Load *, date(date#(`st_trdate`, 'dd-mm-yyyy'),'yyyy-mm') as Period;

//Load *, date(date#([`st_trdate`], 'dd-mm-yyyy'),'yyyy-mm') as Period;

//Load *, date(date#(st_trdate, 'dd-mm-yyyy'),'yyyy-mm') as Period;

LOAD

  `st_account` as %Key.Customer,

  `st_account`,

    `st_trdate`,

    `st_trref` AS %Key.Trans,

    `st_custref`,

    `st_trtype`,

    `st_trvalue`,

    `st_vatval`,

    `st_trbal`,

    `st_paid`,

    `st_crdate`,

    `st_advance`,

    `st_payflag`,

    `st_dueday`,

    `st_type`,

    `st_delacc`,

    id,

    `st_pedate`;

SQL SELECT `st_account`,

    `st_trdate`,

    `st_trref`,

    `st_custref`,

    `st_trtype`,

    `st_trvalue`,

    `st_vatval`,

    `st_trbal`,

    `st_paid`,

    `st_crdate`,

    `st_advance`,

    `st_payflag`,

    `st_dueday`,

    `st_type`,

    `st_delacc`,

    id,

    `st_pedate`

FROM stran;

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
sasiparupudi1
Master III
Master III

Try

date(Floor(st_trdate),'yyyy-mm') as Period

hth

Sas

jonathandienst
Partner - Champion III
Partner - Champion III

Your problem is that you will get mutiple values of each period, with the underlying value being the actual date (ie up to 31 distinct values). The Date() function does not truncate the day when you format with something like 'yyyy-mm', it just does not display it.

You need

    Date(MonthStart(Date#([st_trdate], 'dd-mm-yyyy'),'yyyy-mm')) as Period,

    Date(MonthStart(Date#([st_trdate], 'dd-mm-yyyy')), 'yyyy-mm') as Period,

This ensures that there is only one possible value for each Period.

(edit - bracket placement corrected)

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
PrashantSangle

Hi,

What kind of issue you are facing???

in date format

mm - > minutes

MM -> Month

Check date format also.

Regards,

Prashant

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
muthukumar77
Partner - Creator III
Partner - Creator III

May be like this,

Date(Floor(st_trdate),'YYYY-MM')

Muthukumar Pandiyan
hemachandran
Partner - Creator
Partner - Creator

try this Expression,

=Date(floor(st_trdate),'YYYY-MM')

Anonymous
Not applicable
Author

Thank you for your help this has resolved the problem.