Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
madhubabum
Creator
Creator

Distinct Count Calculation in Script level

Hi Experts,

I am having the following scenario as per my requirement (Move "Distinct Count " calculation to script level)

Dataset :  

TransactionsIDProductIDPname
1100  a
2101  b
3102  c
4103  d
5104  e
2105  f
3106  g

Note : Calculate Distinct Transactions in Script level

In UI Level : Count(Distinct TransactionsID)  = 5,

But Script level calculated field : Count(Dist_TransactionsID) = 7

Here i am attaching the application, excel file..

How we can sort out this issue ,......any help ?

Thanks,

Madhu

1 Solution

Accepted Solutions
jagan
Luminary Alumni
Luminary Alumni

Hi,

Try like this

Temp:

LOAD TransactionsID,

     ProductID,

     Pname

FROM

Test1.xlsx

(ooxml, embedded labels, table is Sheet1);

DistinctTransactions:

Load DISTINCT

TransactionID,

1 as TransCount

Resident Temp;

Now use Sum(TransCount) in frontend. 

Hope this helps you.

Regards,

jagan.

View solution in original post

18 Replies
Digvijay_Singh

Not sure how you want to write script but below script generates count as 5 -

Temp:

LOAD TransactionsID,

     ProductID,

     Pname

FROM

Test1.xlsx

(ooxml, embedded labels, table is Sheet1);

Distinct:

Load

  Count(DISTINCT TransactionsID) as TransCount

Resident Temp

madhubabum
Creator
Creator
Author

Hi Digvijay Singh,

Thanks for ur reply..

But in my scenario, I want to concatenate or join this field to Temp Table...

How we can acheive.

Chanty4u
MVP
MVP

Temp:

LOAD TransactionsID,

     ProductID,

     Pname

FROM

Test1.xlsx

(ooxml, embedded labels, table is Sheet1);

Join  or Concatenate

Distinct:

Load

  Count(DISTINCT TransactionsID) as TransCount

Resident Temp

Anonymous
Not applicable

may be like this you can try?

Temp:

LOAD TransactionsID,

     ProductID,

     Pname

FROM

Test1.xlsx

(ooxml, embedded labels, table is Sheet1);

Let VCount=count(Distinct TransactionsID);

then use this variable at UI?

madhubabum
Creator
Creator
Author

Hi Chanty,

Thanks for ur reply ....

can u please suggest to use "Join"

Note : I am already used left join, But it won't work

Digvijay_Singh

You can use left Join(Temp) in between but it depends how do you want to see the output - I am not able to understand how you would like to use this count in charts.

Chanty4u
MVP
MVP

what do u want the exact output?

jagan
Luminary Alumni
Luminary Alumni

Hi,

Are you couning Distinct TransactionID or TransactionID Count? 

For Distinct:

Count(Distinct TransactionsID)  // Returns 5


Count(TransactionID) // Will give 7


Regards,

Jagan.

PrashantSangle

Hi,

can you post your script??

Regards

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂