Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Displaying the current and previous month value in bar chart with two dimensions.

Hi,

I requirement is to create a barchart with State as its dimension and Sum(No.of.Subscribers) as its expression, where the Sum(No.of.Subscribers) of current and previous months only should be displayed. Please refer to the image below for reference if you dont understand my requirement. I have attached my data. Can someone help!

Untitled.png

1 Solution

Accepted Solutions
sunny_talwar

Ignore selection in Month field

Sum({<MonthYear={"$(=Date(Max(MonthYear), 'MMM-YYYY'))"}, Month>}[No.of.Subscribers])

Sum({<MonthYear={"$(=Date(AddMonths(Max(MonthYear), -1), 'MMM-YYYY'))"}, Month>}[No.of.Subscribers])

View solution in original post

6 Replies
PrashantSangle

Hi,

create 2 expression

1 for current month and 2 for previous month

1: current Month

sum({<Year={"$(=max(Year))"},Month={"$(=max(Month))"}>}[No of Subscribers])

2:

sum({<Year={"$(=max(Year))"},Month={"$(=max(Month)-1)"}>}[No of Subscribers])


check month format might required maxstring instead of max use as per requirement.

Search on community for CYMTD and LYMTD expression


Regards

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
Not applicable
Author

I tried whatever you said, but its not working can you please share me a .qvw file?

sunny_talwar

I think the problem is that your Month field is not read as date and hence you are able to use Max(Month) in set analysis. In your script, try this:

Month(Date#(Month, 'MMM')) as Month,

Num(Month(Date#(Month, 'MMM'))) as MonthNum,


now try using MonthNum in your expression

sum({<Year={"$(=max(Year))"},MonthNum = {"$(=max(MonthNum )"}>}[No.of.Subscribers])

Having said that, I would be concerned about this expression when it's Jan of the year. In that case, I would suggest you to create a month year field and use that in place of Month and Year separately

Date(MakeDate(Year, Month(Date#(Month, 'MMM'))), 'MMM-YYYY') as MonthYear

and then this:

This month:

Sum({<MonthYear={"$(=Date(Max(MonthYear), 'MMM-YYYY'))"}>}[No.of.Subscribers])


Last month:

Sum({<MonthYear={"$(=Date(AddMonths(Max(MonthYear), -1), 'MMM-YYYY'))"}>}[No.of.Subscribers])

Not applicable
Author

I tried using your steps and got the result. But when I click some other month like april, only the values of April is shown. Please check the attached file.

sunny_talwar

Ignore selection in Month field

Sum({<MonthYear={"$(=Date(Max(MonthYear), 'MMM-YYYY'))"}, Month>}[No.of.Subscribers])

Sum({<MonthYear={"$(=Date(AddMonths(Max(MonthYear), -1), 'MMM-YYYY'))"}, Month>}[No.of.Subscribers])

Not applicable
Author

Thank you very much.