Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Highlighted
khanashique
Contributor II

Need to Get current year and previous month data

Hi Experts,

I need to see the sales for current year's previous month's data (this works only if i apply filter gauge and then selects the particular month), how to write a correct expression.

By giving below expression i can get the current years data but when i add months expression it gets failed.

Sum({<Year={'2018'}>}YTD_Sales) --> getting current year sales.

Sum({<Year={'2018'},Month={Max(Month)-1)}>}YTD_Sales) --> expression gets failed does not return any value.

Have tried another expression but no result:

Sum({<Year={'2018'},Month={Month(AddMonths(Now()),-1)}>}YTD_Sales) --> expression gets failed does not return any value.

Thanks,

MAK.

Tags (2)
1 Solution

Accepted Solutions
shiveshsingh
Honored Contributor

Re: Need to Get current year and previous month data

Try this

Sum({<Year={'2018'},Month={"$(=Month(AddMonths(Now(),-1)))"}>}YTD_Sales)

7 Replies
shiveshsingh
Honored Contributor

Re: Need to Get current year and previous month data

Try this

Sum({<Year={'2018'},Month={"$(=Month(AddMonths(Now(),-1)))"}>}YTD_Sales)

vardhancse
Valued Contributor III

Re: Need to Get current year and previous month data

Hi,

can try this for previous month:

Month(AddMonths(Max(Date),-1))

**Date is is your date field you can replace with your actual date field

khanashique
Contributor II

Re: Need to Get current year and previous month data

Thanks Shivesh, It worked...

khanashique
Contributor II

Re: Need to Get current year and previous month data

Hi Sasi,

Thanks for your reply --> Month(AddMonths(Max(Date),-1)) did not worked...


The expression which worked is below that is provided by Shivesh


Sum({<Year={'2018'},Month={"$(=Month(AddMonths(Now(),-1)))"}>}YTD_Sales)


Regards,

MAK.

shiveshsingh
Honored Contributor

Re: Need to Get current year and previous month data

Glad to know it worked

vardhancse
Valued Contributor III

Re: Need to Get current year and previous month data

Hi,

I meant replace Date with your date field and then this expression will work.

If you place Date column which is there not there in your data mart then it will not work.

However above expression mentioned correct is correct is correct but it's hard coded, but if we change the month in filter then it may not show the correct value

khanashique
Contributor II

Re: Need to Get current year and previous month data

Hi Thanks once again,

Yes, i have replaced the Date to my Month Field and it did not worked, yes expression which was provided by Shivesh does not change any value if the month filter is selected...

But the purpose of calculation in expressions solved in summary... (so the expression provided by Shivesh works fine.)

Thanks,

MAK