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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Jan-Hendrik
Partner - Creator
Partner - Creator

Set Analyses with Nested If

Hi all'ya guru's

I'm trying to shorten the following set analyses statement:

if(vPeriod='YTD',
sum( {< yyyyFiscal={"$(vFiscalYYYY)"}, pppFiscal={"<=$(vFiscalPPP)"} >} ton ),
if(vPeriod='MTD',
sum( {< yyyyFiscal={"$(vFiscalYYYY)"}, pppFiscal={"$(vFiscalPPP)"} >} ton )
))

 

Have tried the following as an example, but not working:

sum({< yyyyFiscal={"$(vFiscalYYYY)"}, pppFiscal ={"$(=pick(match($(vPeriod),'YTD','MTD'),{"<=$(vFiscalPPP)"},{"$(vFiscalPPP)"}))" } >} ton )

 

Anyone have an idea of what the correct syntax should be or alternative function to use to bring it all under the same sum()

 

Labels (2)
1 Solution

Accepted Solutions
treysmithdev
Partner Ambassador
Partner Ambassador

Usually, if the only difference in an expression is a single piece of text, you can leverage the variable to change the meaning.

 

In your example, the only difference is highlighted below in the two conditions:

if(vPeriod='YTD',
sum( {< yyyyFiscal={"$(vFiscalYYYY)"}, pppFiscal={"<=$(vFiscalPPP)"} >} ton ),
if(vPeriod='MTD',
sum( {< yyyyFiscal={"$(vFiscalYYYY)"}, pppFiscal={"$(vFiscalPPP)"} >} ton )
))

 

 I would change the whole expression to:

sum( {< yyyyFiscal={"$(vFiscalYYYY)"}, pppFiscal={"$(vPeriodCondition)$(vFiscalPPP)"} >} ton )

 

Where vPeriodCondition = '<=' for YTD or '' for MTD.

Blog: WhereClause   Twitter: @treysmithdev

View solution in original post

3 Replies
agigliotti
MVP
MVP

maybe this:

=sum( {< vPeriod = {'YTD'}, yyyyFiscal={"$(vFiscalYYYY)"}, pppFiscal={"<=$(vFiscalPPP)"} >} ton )
+
sum( {< vPeriod = {'MTD'}, yyyyFiscal={"$(vFiscalYYYY)"}, pppFiscal={"$(vFiscalPPP)"} >} ton )

replacing vPeriod with the field name.

I hope it can helps.

The Power of shining a light on the dark side of your data.
Follow me on my LinkedIn | Know Gamma Informatica at gammainformatica.it
treysmithdev
Partner Ambassador
Partner Ambassador

Usually, if the only difference in an expression is a single piece of text, you can leverage the variable to change the meaning.

 

In your example, the only difference is highlighted below in the two conditions:

if(vPeriod='YTD',
sum( {< yyyyFiscal={"$(vFiscalYYYY)"}, pppFiscal={"<=$(vFiscalPPP)"} >} ton ),
if(vPeriod='MTD',
sum( {< yyyyFiscal={"$(vFiscalYYYY)"}, pppFiscal={"$(vFiscalPPP)"} >} ton )
))

 

 I would change the whole expression to:

sum( {< yyyyFiscal={"$(vFiscalYYYY)"}, pppFiscal={"$(vPeriodCondition)$(vFiscalPPP)"} >} ton )

 

Where vPeriodCondition = '<=' for YTD or '' for MTD.

Blog: WhereClause   Twitter: @treysmithdev
Jan-Hendrik
Partner - Creator
Partner - Creator
Author

Awesome, thanks, that did the trick