Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
msmichael
Creator
Creator

daily data to weekly

Hi experts,

I have three fields in my qvw, some of data looks like below,

reportIdreportDatepageCount
14/30/2019100
15/1/2019102
15/2/2019110
15/6/2019130
.........

 

for each reportId, I have many reportDate (not necessarily for everyday,  some dates could be missing), on each reportDate, I have a pageCount number.

I want to get a weekly stat. So, for each week, I need to get the most recent (closest reportDate to the week end date) pageCount for each reportId, then I sum up the pageCount to get the total number for the week.

so, in the attached qvw file, I should get below result,

weekTotal
18330
19475
20531
21600

 

The expression I am using only gives me the last week number..

How can I do it?

The qvw file is attached.

 

Thanks,

Michael

1 Solution

Accepted Solutions
Vegar
MVP
MVP

To get highest pagecount per reportId and Week in dimension

=FirstSortedValue (pageCount, -pageCount)

 

The sum of highest pagecount per reportid and week (not dependent on the dimension in chart)

=sum(aggr(max(pageCount), Week,reportId))

image.png

View solution in original post

7 Replies
msmichael
Creator
Creator
Author

to clarify, if I have data in below table,

reportIdreportDatepageCount
104/30/2019100
105/01/2019105
105/02/2019110
105/06/2019130
105/07/2019135
105/08/2019140
105/09/2019145
105/13/2019165
105/14/2019170
105/15/2019175
105/16/2019180
105/20/2019200
204/30/2019100
205/02/2019110
205/06/2019130
205/07/2019135
205/08/2019140
205/09/2019145
205/10/2019150
205/13/2019165
205/14/2019170
205/15/2019190
205/16/2019170
205/20/2019200
304/30/2019100
305/01/2019105
305/02/2019110
305/06/2019130
305/07/2019135
305/08/2019140
305/09/2019165
305/10/2019180
305/13/2019165
305/14/2019170
305/15/2019175
305/16/2019181
305/20/2019200

 

First step is to get the latest pageCount for each reportId and each week, below is the result I expect, (also highlighted in the above table in red)

reportIdweekpageCount
118110
119145
120180
121200
218110
219150
220170
221200
318110
319180
320181
321200

 

then I need to sum up the pageCount for each week, then I get this as the final result,

weekTotal
18330
19475
20531
21600

 

 

Vegar
MVP
MVP

To get highest pagecount per reportId and Week in dimension

=FirstSortedValue (pageCount, -pageCount)

 

The sum of highest pagecount per reportid and week (not dependent on the dimension in chart)

=sum(aggr(max(pageCount), Week,reportId))

image.png

msmichael
Creator
Creator
Author

Hi Vegar,

Thank you for your reply. 

Actually I don't want to get the "highest" pagecount per reportId and Week, I want to get the "latest" pagecount per reportId and Week. For example, for reportId=1, if there's a pagecount number on Friday in a week, I'll use this number, if not, I'll use the Thursday's pagecount number, and if there's no Thursday number, I'll use Wednesday's, and so on..

After I get the "latest" pagecount for each reportId in each Week, I need to sum them up grouping by Week, so I get the total pagecount of all reports for each week..

How do I do this?

Thanks,

Michael

Vegar
MVP
MVP

The firts sorted value approach is easy to adjust. 

=FirstSortedValue (pageCount, -reportDate)

image.png

msmichael
Creator
Creator
Author

Hi,

In my bar chart, I'm using below calculated dimension: (because I want to get weekly summary)

=WeekEnd(reportDate)

 

I want to embed the FirstSortedValue function into aggr, I'm using below expression:

=sum(aggr(FirstSortedValue(pageCount, -reportDate), reportId, WeekEnd(reportDate)))

However, I got "No data to display".. how to make it work?

my qvw attached..

thanks

 

msmichael
Creator
Creator
Author

Hi,

I figured, changed the expression a little bit, now it works.

=sum(aggr(FirstSortedValue(pageCount,-reportDate ), Week, reportId))

thanks for the help!

Michael 

Vegar
MVP
MVP

Great!
glad it worked out for you.