# New to Qlik Sense

If you’re new to Qlik Sense, start with this Discussion Board and get up-to-speed quickly.

Announcements
QlikWorld 2023, a live, in-person thrill ride. Save \$300 before February 6: REGISTER NOW!
cancel
Showing results for
Did you mean:
Contributor III

## Grouping current month and last month in a bar chart

I need to compare the current month against last month in a bar chart and I need it look like the 7-day rolling bar chart, but I need to retain the date value. When the bar chart is day of the week (instead of date), this week vs last week is grouped automatically. (NB: 30-day rolling comparison legend is incorrect and should say this month, last month) How do I make a side-by-side comparison for the second chart?

Ben

Labels (3)

• ### Visualization

2 Solutions

Accepted Solutions
Champion III

Create a new field based on your Date field as below

Day(Datefield) as DayNum

Then use DayNum as dimension in chart

Or in chart use below calculated dimension

Dimension

=Day(Datefield)

=Month

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

Create a Dual() value field  as below

example

DummyData:
Date
,Day(Date) as DayNum
,MonthName(Date) as Monthname
,Dual(Text(Date),Day(Date)) as DayText
,ceil(Rand()*100) as randomval
;
load date(today()-recno()) as Date
AutoGenerate(90);

Then in Chart use the Field DayText as dimension

example Measures:

CurrentMonth

sum({<Date={">=2022-10-01<=2022-10-30"}>}randomval)

PReviousMonth

sum({<Date={">=2022-09-01<=2022-09-31"}>}randomval)

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
6 Replies
Champion III

Just use the Day dimension that has value 1,2,3,4,5,---30/31

you cannot have dates like 1-Jan-2022 Next to 1-Feb-2022

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

Thanks - but how do I replace the current dimension with your suggestion? When I add 'Day' into the Field section, I get the following:

Before:

After:

Definition of 'previous 30 days' measure for context:

Champion III

Create a new field based on your Date field as below

Day(Datefield) as DayNum

Then use DayNum as dimension in chart

Or in chart use below calculated dimension

Dimension

=Day(Datefield)

=Month

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

Got DayNum but can I overlay this with the actual dates for the first measure (i.e. current 30-days) on the bar chart

(In below example, 1 = 26/09/2022, 2 = 27/09/2022, etc...)

Thanks again

Ben

Champion III

Create a Dual() value field  as below

example

DummyData:
Date
,Day(Date) as DayNum
,MonthName(Date) as Monthname
,Dual(Text(Date),Day(Date)) as DayText
,ceil(Rand()*100) as randomval
;
load date(today()-recno()) as Date
AutoGenerate(90);

Then in Chart use the Field DayText as dimension

example Measures:

CurrentMonth

sum({<Date={">=2022-10-01<=2022-10-30"}>}randomval)

PReviousMonth

sum({<Date={">=2022-09-01<=2022-09-31"}>}randomval)

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

Yeah, that solution does exactly what I needed it to. Thanks very much for your help!

Tags
Community Browser