Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
qliknexus_kgcru
Partner - Contributor III
Partner - Contributor III

Display Total partial sum per quarter and end of month

Hi All,

I want to display the total partial sum in a cross table.

e.g. Here is my sample data:

YearMonthQuarterSalesCATEGORY
2017January413000A
2017February414000B
2017March415000A
2017April116000B
2017May117000A
2017June118000B
2017July219000A
2017August220000B
2017September221000A
2017October322000B
2017November323000A
2017December324000B
2018January425000A
2018February426000B
2018March427000A
2018April128000B
2018May129000A
2018June130000B
2018July231000A
2018August232000B
2018September233000A
2018October334000B
2018November335000A
2018December336000B

I have selected YEAR=2018 and MONTH=MARCH and it  will show me the selected month, the previous 6 months and the next 5 months like so based on my expression:

YearMonthQuarterSalesCATEGORY
2017September221000A
2017October322000B
2017November323000A
2017December324000B
2018January425000A
2018February426000B
2018March427000A
2018April128000B
2018May129000A
2018June130000B
2018July231000A
2018August232000B

I need to put it in a cross table like this, where it will get the total for the quarter if whole 3 months (Oct, Nov, Dec; Jan, Feb,Mar) are present and if the last month (Sep) of the quarter is present. But, if it only displays the first 2 months (Jul, Aug) of the quarter, it will not show the total:

cross_table.png

I managed to put it in a cross table below, but i'm having a hard time with the total:

cross_table_1.png

Thank you for any help!

1 Solution

Accepted Solutions
sunny_talwar

Try this

=If(SecondaryDimensionality() = 2,

If(Count(TOTAL <FiscalYear, Quarter> DISTINCT {<YearMonth = {"$(='>=' & Date(MonthStart(Max(YearMonth), -6), 'YYYYMM') & '<=' &Date(MonthStart(Max(YearMonth), 5), 'YYYYMM'))"}, Year, Month, Quarter>} YearMonth) <> 3 and

  Max(TOTAL <FiscalYear, Quarter> {<YearMonth = {"$(='>=' & Date(MonthStart(Max(YearMonth), -6), 'YYYYMM') & '<=' &Date(MonthStart(Max(YearMonth), 5), 'YYYYMM'))"}, Year, Month, Quarter>} YearMonth) <>

  MonthStart(QuarterEnd(Max(TOTAL <FiscalYear, Quarter> {<YearMonth = {"$(='>=' & Date(MonthStart(Max(YearMonth), -6), 'YYYYMM') & '<=' &Date(MonthStart(Max(YearMonth), 5), 'YYYYMM'))"}, Year, Month, Quarter>} YearMonth))), 0,

  Sum({<YearMonth = {"$(='>=' & Date(QuarterStart(MonthStart(Max(YearMonth), -6)), 'YYYYMM') & '<=' &Date(MonthStart(Max(YearMonth), 5), 'YYYYMM'))"}, Year, Month, Quarter>}Sales)),

Sum({<YearMonth = {"$(='>=' & Date(MonthStart(Max(YearMonth), -6), 'YYYYMM') & '<=' &Date(MonthStart(Max(YearMonth), 5), 'YYYYMM'))"}, Year, Month, Quarter>}Sales))

Capture.PNG

View solution in original post

10 Replies
sunny_talwar

Check this

=If(SecondaryDimensionality() = 2 and Count(TOTAL <FiscalYear, Quarter> DISTINCT {<YearMonth = {"$(='>=' & Date(MonthStart(Max(YearMonth), -6), 'YYYYMM') & '<=' &Date(MonthStart(Max(YearMonth), 5), 'YYYYMM'))"}, Year, Month, Quarter>} YearMonth) <> 3 and

  Max(TOTAL <FiscalYear, Quarter> {<YearMonth = {"$(='>=' & Date(MonthStart(Max(YearMonth), -6), 'YYYYMM') & '<=' &Date(MonthStart(Max(YearMonth), 5), 'YYYYMM'))"}, Year, Month, Quarter>} YearMonth) <>

  MonthStart(QuarterEnd(Max(TOTAL <FiscalYear, Quarter> {<YearMonth = {"$(='>=' & Date(MonthStart(Max(YearMonth), -6), 'YYYYMM') & '<=' &Date(MonthStart(Max(YearMonth), 5), 'YYYYMM'))"}, Year, Month, Quarter>} YearMonth))), 0,

Sum({<YearMonth = {"$(='>=' & Date(MonthStart(Max(YearMonth), -6), 'YYYYMM') & '<=' &Date(MonthStart(Max(YearMonth), 5), 'YYYYMM'))"}, Year, Month, Quarter>}Sales))

Capture.PNG

qliknexus_kgcru
Partner - Contributor III
Partner - Contributor III
Author

‌Hi,

Thank you for your answer. Is it possible for the Q2 total to have the total not only for Sep, but also includes Jul, Aug, & Sep total?

sunny_talwar

Try this

=If(SecondaryDimensionality() = 2,

If(Count(TOTAL <FiscalYear, Quarter> DISTINCT {<YearMonth = {"$(='>=' & Date(MonthStart(Max(YearMonth), -6), 'YYYYMM') & '<=' &Date(MonthStart(Max(YearMonth), 5), 'YYYYMM'))"}, Year, Month, Quarter>} YearMonth) <> 3 and

  Max(TOTAL <FiscalYear, Quarter> {<YearMonth = {"$(='>=' & Date(MonthStart(Max(YearMonth), -6), 'YYYYMM') & '<=' &Date(MonthStart(Max(YearMonth), 5), 'YYYYMM'))"}, Year, Month, Quarter>} YearMonth) <>

  MonthStart(QuarterEnd(Max(TOTAL <FiscalYear, Quarter> {<YearMonth = {"$(='>=' & Date(MonthStart(Max(YearMonth), -6), 'YYYYMM') & '<=' &Date(MonthStart(Max(YearMonth), 5), 'YYYYMM'))"}, Year, Month, Quarter>} YearMonth))), 0,

  Sum({<YearMonth = {"$(='>=' & Date(QuarterStart(MonthStart(Max(YearMonth), -6)), 'YYYYMM') & '<=' &Date(MonthStart(Max(YearMonth), 5), 'YYYYMM'))"}, Year, Month, Quarter>}Sales)),

Sum({<YearMonth = {"$(='>=' & Date(MonthStart(Max(YearMonth), -6), 'YYYYMM') & '<=' &Date(MonthStart(Max(YearMonth), 5), 'YYYYMM'))"}, Year, Month, Quarter>}Sales))

Capture.PNG

qliknexus_kgcru
Partner - Contributor III
Partner - Contributor III
Author

Hi Sunny,

Thank you so much for your answer! it worked well! one more thing, I've tried to hide the Fiscal Year and Quarter column from the pivot table but it seems to mess up the calculation. can i hide the Fiscal Year and Quarter column while retaining the correct values of the table? thanks!

sunny_talwar

Like this?

Capture.PNG

qliknexus_kgcru
Partner - Contributor III
Partner - Contributor III
Author

‌yes! How did you do that?

sunny_talwar

I have already attached the qvw sample with my response above... did you get a chance to look at it?

Re: Display Total partial sum per quarter and end of month

qliknexus_kgcru
Partner - Contributor III
Partner - Contributor III
Author

‌yes i have checked it, it works well for me.

sunny_talwar

Awesome, I am glad I was able to help