Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Add previous month to selection

hi!!

i v got tu do a graphic and chart of sells by month

but i want to compare previous month to selected month always

i do this :

=sum({$<month={$(=AddMonths(month,-1))}>} sells)

but it doesnt work

obviously because for exemple then i selected sptember there s no month agust in selected records, there s only september records !

how can i do that ???

13 Replies
Not applicable
Author

nothing append!!

my date date_ma is in 'MM-YYYY' format

i create a variable vDatemun : =date(AddMonths(date_ma, -1),'MM-YYYY')

i create a grpahic with no dimension and 2 expressions:

1) =Sum({<date_ma={"=$(=Max(date_ma))"}>} MCD_B)

2)=Sum({<date_ma={'=$(vDatemun)'}>}MCD_B)

when i select september, it displays the same total of september !

Not applicable
Author

If your date format is 'MM-YYYY', something like this should work:


Create a variable "VAR_PreviousMonth" whit this expression:

=Date(AddMonths(YourDateFieldHere, -1), 'MM-YYYY')

And, next, in your graph's expressions, try this

Sum({<YourMonthFieldHere={'$(VAR_PreviousMonth)'}>} YourValueFieldHere)

Good Luck!

Bruno Oliveira

kaicpa2
Contributor III
Contributor III

Hello King-greg

I had the same problem and solved in this way

Legenda

Period = date gained from a excel file like a number

Qty = is the dimension I want to sum up. For you is sells

First,I have created a variable:

vMonthDelta= date(Period,'DD/MM/YYYY')- MonthStart(Period,-1 )

Then in the chart expression:

Current month :  Sum({$<Period ={$(=( Period))} >} Qty)

Previous month: Sum({$<Period ={$(=( Period)-vMonthDelta)} >} Qty)

see if it works in this way

Br

Carlo

 

Not applicable
Author

If you can modify your data model you could do something like:

SalesPeriods:

Load MaxString(Period) as Period,

RowNo() as PeriodRank

Resident SalesData

group by Period

order by Period desc;

Now your sales data periods are ranked so instead of comparing to dates you can use the current sales period based on rank of 1, and the previous sales period would be rank of 2 even if it was really several months in the past.

Not sure if that will help you or if your situation is much more complicated than just having missing months of data.