Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
jazzsran
Partner - Contributor III
Partner - Contributor III

Cumulative Sum in stacked Bar Chart in QlikSense

Hi,

I have stacked barchart, with two dimensions country and YearMonth and a measure sum(Sales) but for each country the source for sales is different, also the field names are different. suppose sales1 and sales2

I am using if statement on country to guide to the correct calculative statement which is working fine.

if(country='J',sum(sales1),if(country='I',Sum(Sales2)))

Now, there is a requirement that one of sales is already cumulative other should be calculated in the chart.

When I apply this formula only on that country it works fine, but when I add it in the If statement related data just disappeared and country from the chart.

if(country='J',sum(sales1),if(country='I',Aggr(RangeSum(Above(Sum(sales2), 0, RowNo())),YearMonth)))

Could anyone please guide me?

Thanks

Labels (2)
4 Replies
rubenmarin

Hi, I'm not sure but maybe adding country to the aggr():

Aggr(RangeSum(Above(Sum(sales2), 0, RowNo())),YearMonth,Country)

jazzsran
Partner - Contributor III
Partner - Contributor III
Author

Hi,

No, it doesn't work as country is one of the dimension for the bar chart.

Issue is if I select any country the bar chart selects it and it works fine.

but with the expression in the measure for the bar chart:

if(country='J',sum(sales1),if(country='I',Aggr(RangeSum(Above(Sum(sales2), 0, RowNo())),YearMonth)))

The country 'I' disappears rest is shown. However still with this if I select 'I' from filters, the data appears in the same bar chart. very strange...

 

normally:

jazzsran_0-1687163353373.png

when filter on 'I', only "I" appears:

jazzsran_1-1687163415044.png

is it possible Rangesum or Aggr doesn't work in If statements?

I am thinking of calculating the cumulative sum in the script for 'I' as well, others are already cumulative.

Thanks,

 

barnabyd
Partner - Creator III
Partner - Creator III

G'day @jazzsran,

I would bypass the problem by creating a new column in the load script according to your formula ...

rangesum( sales1, Sales2, ... ) as Sales

Then the expression in the chart becomes a normal aggregation.

I hope this helps. Cheers, Barnaby.

Barnaby Dunn
BI Consultant
jazzsran
Partner - Contributor III
Partner - Contributor III
Author

Hi,

Sorry for late reply.

@barnabyd , while your solution might work, I actually created a cumulated sum for another Sales as well and displayed on the chart. It worked fine.

Thanks