Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
dana
Creator III
Creator III

Compare current & previous periods with column dims

Hi People,

I need to design a pivot which will enable comparing 2 periods, with a dynamic selection of periods.

Current period can be from date - to date, based on the user selection in the calendar.

Previous period - is calculated for the previous year.

So the same expressions are displayed for both periods.

I would appreciate some tips for achieving it.

Thanks!

PIVOT  current and previous.png

Labels (1)
1 Solution

Accepted Solutions
dana
Creator III
Creator III
Author

Hi,

I defined two variables for the current and previous periods:

vCurrentPeriod: 

=Dual(Date(YearStart(Min(MonthDate))) & '-' & Date(Max(MonthDate)),2)

vPreviousPeriod:

= Dual(Date(YearStart(Min(MonthDate),-1)) & '-' & Date(AddYears(Max(MonthDate),-1)),1)

I used ValueList to create my periods dimension in the pivot table:

=ValueList(vCurrentPeriod,vPreviousPeriod)

I added to the expressions an If:

=If(ValueList(vCurrentPeriod,vPreviousPeriod) =vCurrentPeriod,
Sum({<Year = {'$(vCurrentYear)'},Date={"<=$(vMaxDate)"}>}CountEntries_Monthly),
Sum({<Year = {'$(vPreviousYear)'},Date={"<=$(vMaxDate_PrevYear)"}>}CountEntries_Monthly))

And it does what I want!

 

View solution in original post

3 Replies
vinieme12
Champion III
Champion III

Use a Calculated Dimension in this case

 

Row Dimension

=Supplier

 

Column Dimension

Period (level1)

=  Aggr( only({<Datefield = {">=$(=YearStart(Max(Date)))<=$(=Max(Date))"}>+<Datefield = {">=$(=YearStart(Max(Date),-1))<=$(=AddYears(Max(Date),-1))"}> }Datefield )   ,Datefield)

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
dana
Creator III
Creator III
Author

Hi Vineeth,

After applying the expression, looks like the ranges are calculated properly:

 

CALCULATED PERIODS 1.png  The issues are:

Current period shows only the month selected, and not the range.

The previous periods are calculated properly, but not displayed at all in the pivot.

Please see the filter object

CALCULATED PERIODS 2.png

I can't figure out the reason for that..

Edit: 

In the pivot table, I don't want to show the months, but the relevant range only...

Is it feasible? 

How would the table expression sync with it?

Will appreciate your help.

Thanks a lot!

dana
Creator III
Creator III
Author

Hi,

I defined two variables for the current and previous periods:

vCurrentPeriod: 

=Dual(Date(YearStart(Min(MonthDate))) & '-' & Date(Max(MonthDate)),2)

vPreviousPeriod:

= Dual(Date(YearStart(Min(MonthDate),-1)) & '-' & Date(AddYears(Max(MonthDate),-1)),1)

I used ValueList to create my periods dimension in the pivot table:

=ValueList(vCurrentPeriod,vPreviousPeriod)

I added to the expressions an If:

=If(ValueList(vCurrentPeriod,vPreviousPeriod) =vCurrentPeriod,
Sum({<Year = {'$(vCurrentYear)'},Date={"<=$(vMaxDate)"}>}CountEntries_Monthly),
Sum({<Year = {'$(vPreviousYear)'},Date={"<=$(vMaxDate_PrevYear)"}>}CountEntries_Monthly))

And it does what I want!