Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

mohan_1105
Contributor III

How to write set analysis using Addmonth() ?

Hi,

I wanted to calculate the # of transaction from one month before the particular date and one month after the particular date irrespective of year. To explain it well, Let the particular date be 14-May-1995. You have a transaction data, I need to find whether the customer had any transaction in date between 14-Apr to 14-Jun in all year.

I followed this thread, Using date ranges in set analysis and taken some Inputs. In a straight table, I wrote the set analysis as follows,

count({$<[Bill.DDMM] = {">=(Date(addmonths(max([DOB]), -1), 'DD-MM'))<=(Date(addmonths(max([DOB]), 1), 'DD-MM'))"}>} distinct Year(BillDate)) it doesn't worked.

To check my Date field, I wrote the if condition as follows,

if([Bill.DDMM] > Date(addmonths(max([DOB]), -1), 'DD-MM') and [Bill.DDMM] < Date(addmonths(max([DOB]), 1), 'DD-MM'),1,0) it works fine. I came to know that there is something wrong with my set analysis. It taking my time to rectify the problem. Please help !!


Thanks in Advance!!


Mohan

Tags (1)
1 Solution

Accepted Solutions

Re: How to write set analysis using Addmonth() ?

Try this

Count(DISTINCT Aggr(If(SetDateYear(BillDate, Today()) >= AddMonths(SetDateYear(DOB, Today()), -1) and SetDateYear(BillDate, Today()) <= AddMonths(SetDateYear(DOB, Today()), 1), Year(BillDate)), CustomerCode, BillDate, DOB))

Capture.PNG

12 Replies

Re: How to write set analysis using Addmonth() ?

May be try this

Count({$<[Bill.DDMM] = {">=$(=Date(AddMonths(Max([DOB]), -1), 'DD-MM'))<=$(=Date(AddMonths(Max([DOB]), 1), 'DD-MM'))"}>} DISTINCT Year(BillDate))

Re: How to write set analysis using Addmonth() ?

Try this.

count({$<[Bill.DDMM] = {">=$(=Date(addmonths(max([DOB]), -1), 'DD-MM'))<=$(=Date(addmonths(max([DOB]), 1), 'DD-MM'))"}>} distinct Year(BillDate))


Regards,

Kaushik Solanki

mohan_1105
Contributor III

Re: How to write set analysis using Addmonth() ?

Hi Sunny & Kaushik,

I even tried it before it doesn't work. I just added the sample file.

Thank,

Mohan

Re: How to write set analysis using Addmonth() ?

What is the expected output and in what type of object?

mohan_1105
Contributor III

Re: How to write set analysis using Addmonth() ?

Hi sunny,

I am doing it in the straight table. Expected is straight forward in my expression which I wrote in question. To be more clear, To calculate How many years he purchased with me near to his DOB date.

Thanks!!

Re: How to write set analysis using Addmonth() ?

I was hoping to see a numeric form of output and not expressional form of output

mohan_1105
Contributor III

Re: How to write set analysis using Addmonth() ?

Hi Sunny,

Expected table as follows,

Capture.JPG

Also please take a look at the Excel file attached with this reply.

I hope you can understand what I am looking after. Need help !!

Re: How to write set analysis using Addmonth() ?

Try this

Count(DISTINCT Aggr(If(SetDateYear(BillDate, Today()) >= AddMonths(SetDateYear(DOB, Today()), -1) and SetDateYear(BillDate, Today()) <= AddMonths(SetDateYear(DOB, Today()), 1), Year(BillDate)), CustomerCode, BillDate, DOB))

Capture.PNG

Re: How to write set analysis using Addmonth() ?

Or this

Count(DISTINCT Aggr(If(SetDateYear(BillDate, Today()) >= AddMonths(SetDateYear(DOB, Today()), -1) and SetDateYear(BillDate, Today()) <= AddMonths(SetDateYear(DOB, Today()), 1), Year(BillDate)), CustomerCode, BillDate))

Community Browser