Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Current vs Previous Month expression

Hi!

I have an a table like:

     

   

MonthsJan
Business GroupFTEHeadcountCurrent Month vs Previous Months
A107.31170
B5.3560
c57.82740
d49.99550

My expression is: Count(Employee)

Does anybody know how to write an expression for calculation of difference Month vs Previous month. For example February vs January?

I used an expression like: Count(Employee)- before(Count(Employee) but it shows me null when a selection of month is made.

24 Replies
sunny_talwar

Month isn't one of your dimension in the chart it seems, why don't you use set analysis to do this?

=(Count({<MonthYear = {"$(=MonthName(AddMonths(Max(MonthYear), - 1)))"}>} Employee)/Count({<MontName(MonthYear = {"$(=Max(MonthYear)))"}>} Employee)) - 1

Note: MonthYear is a field that will be created in your load script using MonthName() function.

HTH

Best,

Sunny

Not applicable
Author

it's not working

sunny_talwar

Can you share a sample. The field names you are using and formats you have might look differently.

Sunny

Not applicable
Author

Create the variables:

vMax_Date =Date(Max(Date),'DD/MM/YYYY')

vMin_Date =Date(Min(Date),'DD/MM/YYYY')

v_MTD_Start=Date(Monthstart(vMax_Date),'DD/MM/YYYY')

v_MTD_End=Date((vMax_Date),'DD/MM/YYYY')

v_MTD_LY_Start=Date(MonthStart(AddMonths(vMax_Date,-1)),'DD/MM/YYYY')

v_MTD_LY_End=Date((AddMonths(vMax_Date,-1)),'DD/MM/YYYY')

then, the expression in text box:

='Current Month: ' & Num(count( {<Month=,Date ={">=$(=v_MTD_Start)<=$(=v_MTD_End)"} >} [Employee]),'###0')
& chr(10)
&
'Last Month: '& Num(count( {<Month=,Date ={">=$(=v_MTD_LY_Start)<=$(=v_MTD_LY_End)"} >} [Employee]
),'###0')

or break both the expressions and use as two expression in table chart

Not applicable
Author

Nope, it's not what is required

Not applicable
Author

Now if someone selects February in Month list-box, then it will give the counts related to Feb in current month and

counts related to Jan in previous month

mohammadkhatimi
Partner - Specialist
Partner - Specialist

hope this helps you:-


Count(Employee)- (Count({<MonthYear = {"$(=MonthName(AddMonths(Max(MonthYear), - 1)))"}>} Employee)


Regards

Mohammad

JustinDallas
Specialist III
Specialist III

This doesn't remotely answer your question, but in the future, you might want to consider using a Timeline table.  It will really make such calculations like this easier.

buzzy996
Master II
Master II

try this,

CM:

sum({$<Year = {$(=only(Year) - $(=if(only(Month) = 1, 1, 0)))}, Month = {$(=month(MonthYear))}>} LineSalesAmount)

PM:

sum({$<Year = {$(=only(Year) - $(=if(only(Month) = 1, 1, 0)))}, Month = {$(=month(addmonths(MonthYear, -1)))}>} LineSalesAmount)