Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Shivam22
Contributor III
Contributor III

Qlik Conditional logic

Hi All,

Can you please help me understand how to resolve below 

ID Name Date Product
123 John 1/1/2023 TV
234 John 2/1/2024 TV
345 John 2/2/2024 TV
456 John 3/4/2024 TV
567 John 3/6/2024 Speaker

 

I have to create two columns in above table with two conditions

Condition 1 - If John buying TV after one year from initial purchase and the next purchase after one year from last purchase then its New purchase  but if he changes Product like Speaker in the same Year then its New ,if not Existing - Always initial purchase is New

Condition 2 - If John buying TV or Speaker after one year from initial purchase and the next purchase after one year from last purchase then its New purchase if not Existing - Always initial purchase is New

Results Like below

ID Name Date Product Condition 1 Condition 2
123 John 1/1/2023 TV New New
234 John 2/1/2024 TV New New
345 John 2/2/2024 TV Existing Existing
456 John 3/4/2024 TV New New
567 John 3/6/2024 Speaker New Existing

 

Thanks in Advance!

 

 

Labels (4)
1 Reply
HirisH_V7
Master
Master

Hi look into this,

LOAD
    ID,
    Name,
    Date(Date#(Date, 'M/D/YYYY')) as Date,
    Product,
    If((Date - Previous(Date)) >= 365, 'New', 'Existing') as New/Existing, 

    // Condition 1
    If(RowNo()=1, 'New',
        If(Product <> Previous(Product) and Year(Date)=Year(Previous(Date)), 'New',
        If(Year(Date)-Year(Previous(Date)) >= 1, 'New', 'Existing'))
    ) as [Condition 1],

    // Condition 2
    If(RowNo()=1, 'New',
        If(Year(Date)-Year(Previous(Date)) >= 1, 'New', 'Existing')
    ) as [Condition 2]

Resident YourTable
Order By Name, Date;
HirisH