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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
FelipeB
Contributor II
Contributor II

Count the number of occurrences above (string)

Greetings, everyone.

 

Basically I need to count the number of accurrences of the second column (ConcatNCM) from that line above. The first column (NúmerodaLinha) represents the row number from database.

I'm lost . I've already tried 

 

=RangeCount(Above(Count(ConcatNCM),0,RowNo()))

=RangeCount(Above(Count(ConcatNCM),0,NúmerodaLinha()))

 

The answer on the fourth column should be 1,2,3,4 and 5 respectively.

 

 Captura de tela 2024-11-21 154829.png

Labels (1)
1 Solution

Accepted Solutions
Kushal_Chawda

@FelipeB  try below expression

sum(aggr(rangesum(above(Count(NúmerodaLinha),0,RowNo())),ConcatNCM, NúmerodaLinha))

View solution in original post

4 Replies
pedrohenriqueperna
Creator III
Creator III

Boa tarde, apanhei com essa ai também. Ai pensei em usar o "modifier" padrão da tabela utilizando Count(ConcatNCM), definindo o modificador como "accumulation" e o "range" full.

Se preferir, segue a expressão gerada automatica, mas é bem bagunçada:

Sum({1<[$(=Replace(GetObjectField(0),']',']]'))]={">=$(=Min([$(=Replace(GetObjectField(0),']',']]'))]))<=$(=Max([$(=Replace(GetObjectField(0),']',']]'))]))"},[$(=Replace(GetObjectField(1),']',']]'))]={"=Only({1}[$(=Replace(GetObjectField(1),']',']]'))])>='$(=Replace(Replace(MinString([$(=Replace(GetObjectField(1),']',']]'))]),'''',''''''),'$','$''&'''))' and Only({1}[$(=Replace(GetObjectField(1),']',']]'))])<='$(=Replace(Replace(MaxString([$(=Replace(GetObjectField(1),']',']]'))]),'''',''''''),'$','$''&'''))'"}>}Aggr(RangeSum(Above(If(Count([$(=Replace(GetObjectField(0),']',']]'))]) * Count([$(=Replace(GetObjectField(1),']',']]'))]) > 0, ( Count(ConcatNCM) ) + Sum({1<[$(=Replace(GetObjectField(0),']',']]'))]={">=$(=Min([$(=Replace(GetObjectField(0),']',']]'))]))<=$(=Max([$(=Replace(GetObjectField(0),']',']]'))]))"},[$(=Replace(GetObjectField(1),']',']]'))]={"=Only({1}[$(=Replace(GetObjectField(1),']',']]'))])>='$(=Replace(Replace(MinString([$(=Replace(GetObjectField(1),']',']]'))]),'''',''''''),'$','$''&'''))' and Only({1}[$(=Replace(GetObjectField(1),']',']]'))])<='$(=Replace(Replace(MaxString([$(=Replace(GetObjectField(1),']',']]'))]),'''',''''''),'$','$''&'''))'"}>}0), 0), 0, RowNo())), ([$(=Replace(GetObjectField(1),']',']]'))], (Numeric, Ascending), (Text, Ascending)), ([$(=Replace(GetObjectField(0),']',']]'))], (Numeric, Ascending), (Text, Ascending))))

 

therealdees_0-1732303273158.png

 

 

Qrishna
Master
Master

A simple one liner code using load editor script. No need of any complex front end expressions.

TABLE_TEMP:
load *,
AutoNumber(ConcatNCM&'-'&Numer,ConcatNCM) as runningcount
inline [
Numer, ConcatNCM
1001,AAA
2,BBB
3,CCC
4,DDD
1002,AAA
6,CCC
7,CCC
8,EEE
9,BBB
10,CCC
11,CCC
12,EEE
1003,AAA
14,BBB
15,EEE
16,BBB
1004,AAA
18,AAA
19,CCC
20,BBB
];

2494046 - Count the number of occurrences above (string) (1).PNG

Kushal_Chawda

@FelipeB  try below expression

sum(aggr(rangesum(above(Count(NúmerodaLinha),0,RowNo())),ConcatNCM, NúmerodaLinha))
FelipeB
Contributor II
Contributor II
Author

Thank you, @Kushal_Chawda .

How do I convert it into a SQL formula on LOAD Section?

FelipeB_1-1733507019809.png

Unfortunately I realized that this formula may not work as intended when user apply filters.

Therefore I need to create pre-calculated collumn with the same formula.