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: 
marikabi
Creator
Creator

total traffic in the last week

Hi all,

I am trying to calculate the total traffic volume in the last week for which I have reports.

I am using this formula:

sum({$<WEEK = {"$(=max(WEEK))" }> } [TRAFFIC])

What I need, is to also put a condition on the traffic volumes: I need the last week volume, where the total volume is >0.

Could you please help me?

Many thanks,

Marika

18 Replies
Anil_Babu_Samineni

First try as Static and then we can discuss, If values comes then we may think better opportunity

sum({$<WEEK = {'02'}, YEAR={'2017' } , [TRAFFIC] = {">0"} >} [TRAFFIC])  

or

If(Len(Sum([TRAFFIC]))>0,sum({$<WEEK = {'02'}, YEAR={'2017' } >} [TRAFFIC]))

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
marikabi
Creator
Creator
Author

Using the condition WEEK=2 it does work, giving me the correct traffic value, using both the formulas...

trdandamudi
Master II
Master II

May be as below:

=sum({$<WEEK = {'$(=max(Week))'} > * <TrafficVolume= {'>0'}>} [TRAFFIC])

Note: Please make sure that the field names are correct because they are case sensitive

marikabi
Creator
Creator
Author

hi,

it doesn't work...

trdandamudi
Master II
Master II

Can you please provide sample data with expected output..

marikabi
Creator
Creator
Author

Ok,

this is an extract of a pivot, where I have for each country a traffic volume (note that in the data source for each country I have more cities).

For this "last week traffic" I am using the dimension WEEK (not WEEK_YEAR).

So I expect to obtain for 2016 : 7,993,584

and for 2017: 29,403,008

   

WEEK_YEAR2_171_1752_1651_1650_1649_16
COUNTRY TRAFFIC (min) TRAFFIC (min) TRAFFIC (min) TRAFFIC (min) TRAFFIC (min) TRAFFIC (min)
A8,725,8146,926,5853,592,1486,146,0498,554,3128,336,841
B4,846,7702,978,479805,0383,139,2714,465,5764,411,841
C8,506,2416,498,7151,745,3815,733,8428,817,4568,707,397
D4,980,4852,350,3381,012,8163,053,1964,438,5544,447,862
E2,343,6981,675,338838,2011,447,6191,969,2521,925,210
total29,403,00820,429,4557,993,58419,519,97728,245,150

27,829,151

trdandamudi
Master II
Master II

For some reason I am not able to follow your sample. I am attaching a simple sample file here can you take a look and let me know what is your desired output.

Anonymous
Not applicable

Try

=sum(if(Week=aggr(max({$<Traffic Volume={'>0'}>}Week),Year), TrafficVolume,0))

Anil_Babu_Samineni

Okay, Now coming to real scenario try this

sum({$<WEEK = {'$(=Min(Month(AddMonths(Date(MakeDate(2017,02,01),'DD-MM-YYYY'),-1)))+1)'}, YEAR={'2017' } , [TRAFFIC] = {">0"} >} [TRAFFIC])


You can set as per you need, Here the problem is Max(Week) Give only 52nd Week. This case, You should create one flag for that and then try with using Flag


Load *,

          If(Min(Month(AddMonths(Date(DateField,'DD-MM-YYYY'),-1)))+1)='02', 1, 'Flag was incorrect') as Flag1 //DateField-- Your Field Name, I mean which Week, Year, Month Coming from. You should use that Field name to consider as a File

From Data Source;


Then, Try like below


sum({$<Flag1 = {'1'}, YEAR={'2017' } , [TRAFFIC] = {">0"} >} [TRAFFIC]) //This Will give Traffic values for 2017 and 2nd week where Is Not Null.


HTH

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