Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
jjordaan
Valued Contributor

Max value per Cyclic Group

Hi QlikView addicts,

I want to show the stock figures in a line chart.

My dimension is a cyclic group with some calendar dimeniosn like, Year, Quarter, Month, Week, Date.

Within the ERP system everyday it will count the current stock per item and stores the current stock per item in a different table.

I'm using that table in QlikView.

I cannot sum the values because the total stock per item is per day.

So what I thought to do is to retrieve the max value per shown dimension from the Cyclic Group.

Can anybody help me how to retrieve the max value per dimension in my Cyclic Group (Year, Quarter, Month, Week, Date)

I thought it was easy and tried the below expression, but apparently for me it isn't that easy.

Aggr(Sum({<DateNo = {$(=Max(DateNo))}>} StockQuantity), [$(=GetCurrentField([Date-Dimensions]))]))

Thank you all for your help in advance

8 Replies

Re: Max value per Cyclic Group

If possible try to add flag fields in the script for this. Something like:

LOAD

     Date,

     Item,

     StockQuantity,

     if(floor(Date)=floor(YearEnd(Date)),1,0) as IsYearEnd,

     if(floor(Date)=floor(QuarterEnd(Date)),1,0) as IsQuarterEnd,

     if(floor(Date)=floor(MontEnd(Date)),1,0) as IsMontEnd,

     if(floor(Date)=floor(WeekEnd(Date)),1,0) as IsWeekEnd

FROM ....

You can create five simple expression like sum({<IsWeekEnd={1}>}StockQuantity). Use conditional expressions to show/hide these expressions as needed based on the current field from the cyclic group.

I realize the above may not be possible. For example if you don't have stock records for each day for the items. In that case perhaps you can use something like sum(aggr(firstsortedvalue(StockQuantity, -Date),StockItem, [$(=GetCurrentField([Date-Dimensions]))]))


talk is cheap, supply exceeds demand
jjordaan
Valued Contributor

Re: Max value per Cyclic Group

Hi Gysbert,

As always thank you for your help.

I'm not sure if it wil work for me, but I will test it and let you know

ramoncova06
Valued Contributor III

Re: Max value per Cyclic Group

you had a couple of extra brackets here in there, try with this one  $(='['&GetCurrentField([Date-Dimensions])&']')

jjordaan
Valued Contributor

Re: Max value per Cyclic Group

Hi Ramon,

Thank you for your reply.

Unfortunately (for me) your suggestion didn't work.

Max value per Cyclic Group.png

ramoncova06
Valued Contributor III

Re: Max value per Cyclic Group

what values do you get when you add the expression I have you to listbox ?

jjordaan
Valued Contributor

Re: Max value per Cyclic Group

Hi,

Sorry for my late reply. I was traveling and very busy.

When I re-read my post I saw that my question is a bit confusing.

Sorry for that.

What I'm searching for is that if the Cyclic Group is showing Year-week I want the value for the last date of that week (per visible year-week).

If the Cyclic Group is showing Year-month I want the value for the last date of that month (per visible year-month).

Thanks again for your help

ramoncova06
Valued Contributor III

Re: Max value per Cyclic Group

haven't tested this yet, but it seems as you want something like this


Sum({<DateNo p= ({<DateNo = {"$(=Max( total <GetCurrentField([Date-Dimensions])>DateNo))"}>})>} StockQuantity)

ramoncova06
Valued Contributor III

Re: Max value per Cyclic Group

yes tested it and is not working, you might to go with Gysbert approach

Community Browser