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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
louisernould
Contributor III
Contributor III

Count Number of Rows in distinct sums

Hello dear Qlikview's masters,

I got a problem, and I'm sure you could have the solution.

I am calculating (from a big excel file (around 1000000 rows)) a lot of sums.

But, I want to know how many rows I have in my sum (this is my problem )

for example:

CommandQuantity
A

3

A2
A3
B4
B3
B2
B

6

I have : if Command='A' so, sum(Quantity)=8 (3+2+3)), and I want the number of rows (3)

and if Command='B' so, sum(Quantity)=15 (4+3+2+6)), and I want 4

So I think I want a table like this

CommandSumNumber of rows
A83
B154

Does someone have an idea ? In the script or in an expression,...

Thanks in advance

1 Solution

Accepted Solutions
louisernould
Contributor III
Contributor III
Author

I don't find Desmoustier's answer, so I put it here again:

TMP_Réalisé:

LOAD Site,

          Ref,

          Réalisé

          1 as row_count  

FROM [File1];

INNER JOIN (TMP_Réalisé)

LOAD @1 as NumSem,

     @2 as Annee,

     @3 as [PRE Date réalisé]

FROM [File2];

TMP_Date:

LOAD Distinct([PRE Date réalisé]+56) as DatePourRéalisé

Resident TMP_Réalisé;

LET NbDates = NoOfRows('TMP_Date');

FOR i=1 to $(NbDates)

  LET DateChargement = FieldValue('DatePourRéalisé',$(i));

  TableRéalisé:

  LOAD $(DateChargement) as [Date réalisé],

  Site,

  Ref,

  Sum(Réalisé) as QuantitéRéalisé,

  Sum(row_count) as NumberOfRows

  Resident TMP_Réalisé

   Group by Ref, Site;

NEXT

DROP Table TMP_Date;

DROP Table TMP_Réalisé;

View solution in original post

27 Replies
anbu1984
Master III
Master III

Load Command,sum(Quantity),count(Command) group by Command;

Load * Inline [

Command,Quantity

A,3

A,2

A,3

B,4

B,3

B,2

B,6 ];

louisernould
Contributor III
Contributor III
Author

Hi Anbu,

Actually I already try this solution but I have too many rows and too many commands (something like 200000...) So I cannot do it... Or I can start today and I will finish it in 2 weeks

maybe more in an expression ?

JonnyPoole
Former Employee
Former Employee

A Straight Table with Command as the dimension, sum(Quantity) as the 1st expression and count(Command) as the 2nd expression could work.  This will count the # rows from the data model for each unique command.

If you have a unique record identifier in the data model you could also do count(distinct  [UniqueIdentifierFieldName] )

louisernould
Contributor III
Contributor III
Author

It doesn't work...

My mistake, I forgot something: The 'sum' is already in the script

  LOAD

  Command,

  Sum(Quantity) as sum

  from ...

So maybe the Number of row of the sum has to be in the script... I'm a little bit confused...

The Command is not so important, I just want to know if it is possible to count the number of rows of a sum.

anbu1984
Master III
Master III

No it is not possible to count the number of rows of a sum

louisernould
Contributor III
Contributor III
Author

Oh no...

even with a loop ? like:

for each sum,

count (rowno())

Next

or something like that ?

JonnyPoole
Former Employee
Former Employee

To get the number of rows that were used to create a sum, you need to do a count them in the load script using the 1st  suggestion from Anbu above.

1,000,000 records is really not very much so i don't understand the performance issues even if your laptop is small.

How long does it take to run a load script with the sum() function and group by ?

anbu1984
Master III
Master III

No. Why can't you calculate count along with sum?

Anonymous
Not applicable

Hi Louis,

In Below table For A data you want to see in 3 rows for that there should be some other column which we can use to do grouping.

CommandQuantity
B4
B3
B2
B

6

A

3

A2
A3

Can you share your sample .qvw file.

Thanks

Manish