Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Q&A with Qlik - Qlik Cloud Migration: Questions about migrating to Qlik Cloud? Catch the latest replay!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Expression that assumes a selection is made

Hi

I have an expression below

Previous month:  Count({<[Calendar Year/Month] ={'$(vYMLess1)'}, Month= >}     Distinct [Business Partner Parent ID]))

Current  month:  Count({<[Calendar Year/Month] ={'$(vYM)'}, Month= >}     Distinct [Business Partner Parent ID]))


where vYMless1 relates to the previous month and vYM is the current month

so for eg , if  vYM = 201706  , then vYMLess1 = 201705

and Month will be June and May respectively.

The issue I'm having is with the formula relating to the previous month. It only works if I select June and May.  If i only select June, then the previous months formula gives an incorrect answer.


So basically, what i need is to create an expression for the previous month that assumes that a selection is made for the current month and previous month.

Please can you assist.  I hope I have conveyed my message clearly.

Kind regards

Nayan

Labels (1)
17 Replies
Anil_Babu_Samineni
MVP
MVP

If you are selecting Month Field, Could be the reason you are not selecting Year. Can you try selection happen from [Calendar Year/Month] field and then check whether it comes or not. If not, I would suggest you to share sample application to work

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

Can you tell us what expression you have written in both variables.

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Anonymous
Not applicable
Author

Hi

If Year is selected, there is no change.

Actually the formula given above is a simplistic information. My actual formula is as follows which is an aggregation.

Unfortunately i cannot share the model because of sensitivity of information. 

Kind regards

Nayan

sum(aggr(

  

    ( Count({<[Calendar Year/Month] ={'$(vYMLess1)'},

        [Sales Org] = {'RU01'},

        [Target Distribution Channel] = {'31','32'},

        [Business Partner (CRM): Transaction Blocking Reason] -= {25,26},

        [Terrotory Cluster] -= {'05'},

        Counter = {'1'},

        [Trade Channel Name] = {'Traditional Trade'},

        SegmentationMapped={'Gold','Silver', 'Gold+'},

        [Territory Cluster] -= {'Autonom. Distr'},

        Country = {'Russia'},

        Month

        

        >}

        Distinct [Business Partner Parent ID])

+

Count({<[Calendar Year/Month] ={'$(vYMLess1)'},

        [Sales Org] -= {'RU01'},

        [Business Partner (CRM): Transaction Blocking Reason] -= {25,26},

        [Terrotory Cluster] -= {'05'},

        Counter = {'1'},

        [Trade Channel Name] = {'Traditional Trade'},

        SegmentationMapped={'Gold','Silver', 'Gold+'},

          [Territory Cluster] -= {'Autonom. Distr'},

          Country = {'Russia'},

          Month

        

        >}

        Distinct [Business Partner Parent ID]))

    

        , Outlet))

Anonymous
Not applicable
Author

Hi Kaushik

As requested.

vYM

=max([Calendar Year/Month])

vYMLess1  =Year(Date(AddMonths(Makedate(left(Trim($(vYM)),4),Right(Trim($(vYM)),2),'01'),-1)))&Num(Month(Date(AddMonths(Makedate(left(Trim($(vYM)),4),Right(Trim($(vYM)),2),'01'),-1))),'00')

Kind regards

Nayan

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

First of all check of the vYMLess1 is taking any value when you dont select any month?

If yes then you need to check the expression, else you should focus on variable.

I would write it in other way like below.

vYMLess1

=Date(Addmonths(Date(Date#($(vYM),'YYYYMM')),-1,'YYYYMM')

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Anonymous
Not applicable
Author

Hi Kaushik

If i don't select any month, the vYMLess1 is showing correct values.  Thank you for your reply.

Not sure if you seen my expression when i replied to Anil.

Kind regards

Nayan

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

I can see that you have missed the '=' for the Month Field.

Your expression should be.

sum(aggr(

 

    ( Count({<[Calendar Year/Month] ={'$(vYMLess1)'},

        [Sales Org] = {'RU01'},

        [Target Distribution Channel] = {'31','32'},

        [Business Partner (CRM): Transaction Blocking Reason] -= {25,26},

        [Terrotory Cluster] -= {'05'},

        Counter = {'1'},

        [Trade Channel Name] = {'Traditional Trade'},

        SegmentationMapped={'Gold','Silver', 'Gold+'},

        [Territory Cluster] -= {'Autonom. Distr'},

        Country = {'Russia'},

        Month=

       

        >}

        Distinct [Business Partner Parent ID])

+

Count({<[Calendar Year/Month] ={'$(vYMLess1)'},

        [Sales Org] -= {'RU01'},

        [Business Partner (CRM): Transaction Blocking Reason] -= {25,26},

        [Terrotory Cluster] -= {'05'},

        Counter = {'1'},

        [Trade Channel Name] = {'Traditional Trade'},

        SegmentationMapped={'Gold','Silver', 'Gold+'},

          [Territory Cluster] -= {'Autonom. Distr'},

          Country = {'Russia'},

          Month=

       

        >}

        Distinct [Business Partner Parent ID]))

   

        , Outlet))


Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Anonymous
Not applicable
Author

Hi Kaushik

I have added in the "=" sign, however no difference.  Does it make a difference to put an "=".

Kind regards

Nayan

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

I feel it should work.

Only way to look more into is to see actual data.

Please share the sample application.

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!