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

Set Analysis using Left function

My data sctucture:

ProductInvoiced YearInvoiced YearMonthPaid YearMonthAmount
A201220120120120225
A201220120220120550
A201220130320120675
A2012201204201204100
A2013201301201306125
A2013201302201304150
A2013201303201303175
A2013201304201305200

Current Object Expressions:

Current Year Amount:

=Sum ({$<[Incurred Year] = {$(=Max([Incurred Year]))}>}[Amount])

Prior  Year Amount:

'=Sum ({$<[Incurred Year] = {$(=Max([Incurred Year]-1))}>}[Amount])

These expression work fine but I want to add the additonal filter for Paid Year just like I have it for Incurred Year in the expressions. However there is no Paid Year in the data so I am wondering how you can get the left 4 characters from the Paid YearMonth and then use it like is being used for the Incurred Year in the expressions above.

1 Solution

Accepted Solutions
whiteline
Master II
Master II

Hi.

You have to choose some field to make selection, assume [Paid YearMonth].

Then you could use search capabilities of set analysis (selection by expression):

=Sum ({$<[Paid YearMonth] = {"=Left( [Paid YearMonth] ,4)=$(=Left(Max( [Paid YearMonth])), 4)"}>}[Amount])

View solution in original post

6 Replies
jpapador
Partner - Specialist
Partner - Specialist

Why not just make a paid year field in the script.  Left([Paid YearMonth], 4) as PaidYear

zagzebski
Creator
Creator
Author

Unfortunately I am not always in control of the script - as in this case. Also I seem to come across this need at various times when I want to use a just portion of a field in my set analysis in combination with max/min.

whiteline
Master II
Master II

Hi.

You have to choose some field to make selection, assume [Paid YearMonth].

Then you could use search capabilities of set analysis (selection by expression):

=Sum ({$<[Paid YearMonth] = {"=Left( [Paid YearMonth] ,4)=$(=Left(Max( [Paid YearMonth])), 4)"}>}[Amount])

zagzebski
Creator
Creator
Author


Thanks!

So I understand - why aren't we able to just eliminate the middle part and have something like this?:

<[Paid YearMonth] =$(=Left(Max( [Paid YearMonth])), 4)"}>}

Instead of:

<[Paid YearMonth] = {"=Left( [Paid YearMonth] ,4)=$(=Left(Max( [Paid YearMonth])), 4)"}>}

I know there is a good reason. Thanks so much in advance!

whiteline
Master II
Master II

Because Paid YearMonth contains values like YYYYMM, while left(...,4) returns only YYYY.

The suggested set expression filters those  Paid YearMonth values for which the expression between quotes is true.

zagzebski
Creator
Creator
Author

Hi -

I thought this expression was working but when I set it alone in an expression it returns 0 for every line (no mater what I select on the Paid YearMonth list box):

Sum ({$<[Paid YearMonth] = {"=Left( [Paid YearMonth] ,4)=$(=Left(Max( [Paid YearMonth])),4)"}>}[DHP Liability Amount])