Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Count Invoice Lines with Count over Partition by in Qlikview?

Hi,

I have a report in Qlikview that shows Invoice numbers and Invoice Lines (besides other data) and I would like to have a column that counts the number of Invoices Lines contained in an Invoice. Basically, I would like to build a table like this:

Invoice # Invoice LineNum_lines
1a3
1b3
1c3
2a2
2b2
3a4
3b4
3c4
3d4

If I were to do that with a sql statement my query would look like this:

SELECT Inv_num, Inv_line, COUNT(*) OVER(PARTITION BY Inv_num) as Num_lines FROM TABLE1

Is there a way to get something similar in Qlikview?

Kind Regards

Julian

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

First load could be ....

InvTable:

LOAD

     Inv_num,

    1 AS CountFlag

     ... etc

FROM Invoices.xls....

Second load could then be ....

LEFT JOIN (InvTable) LOAD

    Inv_num

    sum(CountFlag) AS CountOfRows

RESIDENT InvTable

GROUP BY Inv_num;

Jonathan

View solution in original post

9 Replies
sujeetsingh
Master III
Master III

hi,

you can try it with loading and then group by ...

Not applicable
Author

Hi,

Would you please be more specific please? Any example?

Anonymous
Not applicable
Author

You can reload the table using a group by Inv_num, and include a field that is either a count of Inv_num or a key, or a sum of a flag '1' created on the first load.

Jonathan

Anonymous
Not applicable
Author

First load could be ....

InvTable:

LOAD

     Inv_num,

    1 AS CountFlag

     ... etc

FROM Invoices.xls....

Second load could then be ....

LEFT JOIN (InvTable) LOAD

    Inv_num

    sum(CountFlag) AS CountOfRows

RESIDENT InvTable

GROUP BY Inv_num;

Jonathan

Not applicable
Author

Hi Julian,

do you need it in the script?

If not, you could use set analysis in an expression:

=Count({1<inv_num={$(=inv_num)}>} Inv_line)

Ciao

Klaus

Not applicable
Author

Hi Jonathan,

Yes! Your answer works like a charm! Thanks a lot!

Not applicable
Author

Hi Klaus,

Thanks for your reply and your solution.I actually like the idea of using set analysis, but unfortunatelly I could not make it work. It launches an "error in calculation"

Regards

Julian

Not applicable
Author

I check with test data, just a moment.

Not applicable
Author

Sorry, can't get that one working - even with aggr.