Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Karin
Contributor III
Contributor III

Bar Chart for Trend Line Slope

Hi All,

I am quite new to Qlik Sense. I need to create a bar chart with bars being slopes of the trend line for sales of the last 12months, rolling.

In Excel, slope is calculated by the formula SLOPE(known_y’s, known_x’s)

The graph would look like this:

Slope.jpg

Bar “Jan-20” shows the slope (measure) of the trend line for sales for the period Feb19-Jan20.

Bar “Dec-19” shows the slope of the trend line for sales for the period Jan19-Dec19, etc.

I know how to get the trendline for 12 months in Qlik Sense. In my case it is the following expression:

linest_m(total aggr(if(Sum({<is12M={1}, AsOfMonth={'$(=vMaxMonthNo)'}>}[Sales]),Sum({<is12M={1}, AsOfMonth={'$(=vMaxMonthNo)'}>}[Sales])),MonthYear),MonthYear)*only(MonthYear)+linest_b(total aggr(if(Sum({<is12M={1}, AsOfMonth={'$(=vMaxMonthNo)'}>}[Sales]),Sum({<is12M={1}, AsOfMonth={'$(=vMaxMonthNo)'}>}[Sales])),MonthYear),MonthYear))

To my understanding, the bold part is the slope. But how to calculated the slopes for rolling 12 months and put them all in one bar chart?

Any help on this is highly appreciated!

25 Replies
Karin
Contributor III
Contributor III
Author

Yes -I also think we are almost there!

Unfortunately I can't share the dashboard.

I did as you suggested - changed the Dimension to AsOfMonthYear. See what happens:

Slope5.JPG

As Measure I have this:

LinEst_M( aggr(sum({<is12M={1},AsOfMonth={">=12<=24"} >}[Sales]), MonthYear, AsOfMonthYear), aggr(Only({<is12M={1},AsOfMonth={">=12<=24"}>}MonthYear), MonthYear, AsOfMonthYear))

As I wrote above, replacing  MonthYear with AsOfMonth is not working.

Thanks!

 

 

 

lorenzoconforti
Specialist II
Specialist II

can you share the excel file you used to produce the chart with the different scale?

 

Karin
Contributor III
Contributor III
Author

Yes-sure. I attach the Excel file with the dummy data and slope calculation.

lorenzoconforti
Specialist II
Specialist II

Try this please:

LinEst_M( aggr(sum({<is12M={1},AsOfMonth={">=12<=24"} >}[Sales]), MonthNo, AsOfMonthYear), aggr(Only({<is12M={1},AsOfMonth={">=12<=24"}>}MonthNo), MonthNo, AsOfMonthYear))

Karin
Contributor III
Contributor III
Author

YES!!! It worked!!  Amazing. Thank you so much!!! I highly appreciate your help!

 

Just to summarize the solution:

Dimension expression:

 =aggr(ONLY({<MonthNo={'13','14','15','16','17','18','19','20','21','22','23','24'}>}AsOfMonthYear),AsOfMonthYear)

Measure expression:

=LinEst_M( aggr(sum({<is12M={1},AsOfMonth={">=12<=24"} >}[Sales]), MonthNo, AsOfMonthYear), aggr(Only({<is12M={1},AsOfMonth={">=12<=24"}>}MonthNo), MonthNo, AsOfMonthYear))

 

lorenzoconforti
Specialist II
Specialist II

Finally! Well done for not giving up