Skip to main content
Announcements
Qlik Community Office Hours - Bring your Ideation questions- May 15th, 11 AM ET: REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
marcel_olmo
Partner Ambassador
Partner Ambassador

Aggregate Challenge

Hi guys, I have one table with two fields "total old" and "total new", and I want to turn "Total Old" in "Total new":

Here's my current table :

myResult.JPG.jpg

And this is my desired result :

Desired.JPG.jpg

What I'm trying to do is if I have four rows like this :

DateNum
20/02/20131
20/03/20132
20/04/20131
20/05/20134
20/06/20136

Get a table like this (with more fields related ) :

DateNum
20/02/20130
20/03/20130
20/04/20130
20/05/20130
20/06/201314

This is my current formula, but it doesn't work :

If(

    MaxString(Years)

    <>

    below(Total MaxString(Years))      

    or       

    MaxString( [Km Group] )

    <>

    below(Total MaxString( [Km Group]  ))

    ,      

    Sum(Total<Years, [Km Group]   > [Total Old] ),' ')

Here I attach my qv document.

Regards, Marcel.

11 Replies
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Marcel,

I compared your document with the Dunphy document, and I think I understand why one document works and another doesn't...

In the working document, the pivot table has 2 dimensions and the expression calculates the total for one of the dimensions. Hence, visually it shows zeros for all the lines except for the last line, where it calculates the overall total.

In your document, however, you have 2 dimensions, and your expression is comparing both dimensions and calculates the total for both dimensions. So, in a way you duplicate the way pivot table works by default:

//sum(  [Total valor recl. Marca]  )

    If(

    MaxString(Years)

    <>

    below(Total MaxString(Years))

    or

    MaxString( [Km Group] )

    <>

    below(Total MaxString( [Km Group]  ))

    ,

    Sum(Total<Years, [Km Group]   > [Total Old] ),' ')

The IF condition will always render true because each row will hold a unique combination of Years and Km Group, and the formula will always calculate the regular sum, because the Total <> has both Dimensions in it - Years and Km Group.

In order to get the effect similar to Dunfy's, I'd think you want to do something like this:

    If(

    MaxString(Years) <> below(Total MaxString(Years))

    ,

    Sum(Total <Years> [Total Old] ),' ')


This should work, unless I misunderstood your requirement.

cheers,

Oleg Troyansky

www.masterssummit.com

/*

    If(

    MaxString(Customer)

    <>

    below(Total MaxString(Customer))

        

    or

         

    MaxString([Item Subgroup])

    <>

    below(Total MaxString([Item Subgroup]))

    ,

        

    Sum(Total<Customer,[Item Subgroup]> [Total Stock Wgt]),' ')

*/

marcel_olmo
Partner Ambassador
Partner Ambassador
Author

THanks Oleg for your try, I know what you mean, but the point is that I need to get the same result as "desired result" (the table with green colour), and if I do the total only for 1 dimension, I won't get a total by year and kilometer group.

Regards, Marcel.