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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
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

27 Replies
demoustier
Creator
Creator

TMP_Réalisé:

LOAD Site,

          Ref,

          Réalisé   

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é,

  1 as row_count

  Resident TMP_Réalisé

   Group by Ref, Site;

NEXT

load* ,sum(row_count) as total_row Resident TableRéalisé group by [Date réalisé];

DROP Table TMP_Date;

DROP Table TMP_Réalisé;

louisernould
Contributor III
Contributor III
Author

Salut Benjamin,

le francais sera peut etre plus clair

en PJ voila un fichier excel pour une date donnée.

Dans mon exemple j'avais pris Command=Site.

ce que je veux, c'est au final une somme des 8 dernieres quantités (de 23 à 31 en gros). Donc un tableau qui me donne le site, la ref, la somme des quantités et le nombre 8

PS les données sont totalement imaginaires

row_count.png

demoustier
Creator
Creator

pourquoi les 8 dernières ? parcequ'elles sont du même site ?

demoustier
Creator
Creator

essaye ça dans le script (je suis parti de ton excel:

TMP:

LOAD Site,

     Ref,

     Quantité,

     [N° Semaine],

     Annee,

     1 as row_count

FROM

C:\Users\ho.bdemoustier\Desktop\Classeur3.xlsx

(ooxml, embedded labels, table is Feuil1) where  [N° Semaine]>= 23;

final:

LOAD

Site,

Ref,

sum(Quantité) as quantité_total,

Annee,

sum(row_count) as nbre_row

Resident TMP group by Annee,Site,Ref;

drop Table TMP

puis un objet Table dans l'appli qui donne:

table final.png

a toi ensuite de mettre une condition plus pertinente pour sélectionner tes 8 dernières lignes

demoustier
Creator
Creator

En partant de ton Excel:

Dans le script:

TMP:

LOAD Site,

    Ref,

    Quantité,

   N_semaine ,

    Annee,

    1 as row_count

FROM

C:\Users\...\Fichier1.xlsx

(ooxml, embedded labels, table is Feuil1) where  N_semaine >= 23;

final:

LOAD

                Site,

                Ref,

                sum(Quantité) as quantité_total,

                Annee,

                sum(row_count) as nbre_row

Resident TMP group by Annee,Site,Ref;

drop Table TMP

puis un objet Table dans l'appli avec les champs :

Site,

Ref,

quantité_total,

Annee,

nbre_row

Le [where  N_semaine>= 23;] dans le script n’est là que pour prendre tes 8 dernières lignes. Tu as surement un critère de sélection plus pertinent à mettre.

Good luck

Benjamin DEMOUSTIER,

De : louis ernould

Envoyé : lundi 22 septembre 2014 17:38

À : DEMOUSTIER Benjamin

Objet : Re:  - Count Number of Rows in distinct sums

Qlik Community<http://community.qlik.com/>

Count Number of Rows in distinct sums

reply from louis ernould<http://community.qlik.com/people/louisernould?et=watches.email.thread> in New to QlikView - View the full discussion<http://community.qlik.com/message/615666?et=watches.email.thread#615666>

louisernould
Contributor III
Contributor III
Author

Well well well...

New day, new challenge. I restarted my computer, qlikview, and my brain this morning, and BIM ! I don't know why, but it's working !!!!!

So thank you Desmoustier (your solution works) and everybody for your help. Sometimes Qlikview is a little bit capricious. 

Louis

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é;

demoustier
Creator
Creator