Qlik Community

QlikView Creating Analytics

Discussion Board for collaboration related to Creating Analytics for QlikView.

Not applicable

Count distinct is not working in script?

Dear community,

I found problem for script below, the FlightNumber is always showing 1...

FlightNumber:

Load Fltno,

    [Flt Dt],

    Count(distinct Fltno) * Count(distinct [Flt Dt])) as FlightNumber

resident FlightData

group by [Flt Dt], Fltno;

I think count distinct might not work in this way in script, anyone knows to workaround to overcome this?

it is working fine in expression in chart.

For special reason, i cannot have expression in the chart, i need a (number of flight) field,

so that the chart can directly use the field.

(limitation of GeoQlik flow chart, only can use field, expression is not working)

I need the number of flight field can corresponding to the filter selection. just like the figure show in blue text box.

Thanks and best regards,

Chanel

1 Solution

Accepted Solutions
MVP
MVP

Re: Count distinct is not working in script?

Hi,

Try any of this expressions

=Sum(Aggr(1, Fltno, [Flt Dt]))

or

= count(DISTINCT Fltno &  Ceil([Flt Dt]))

Regards,

Jagan.

12 Replies
manideep78
Valued Contributor

Re: Count distinct is not working in script?

What exact Calculation do you want over there?

You are taking distinct Fltno and [Flt Dt] for each record. So they both always give 1 and hence 1*1=1.

MVP
MVP

Re: Count distinct is not working in script?

Hi

Since you are grouping by Fltno and Flt Dt, the distinct counts will always be 1, so the count distinct is working correctly. What are you trying to do? Perhaps you should explain how you would like to determine FlightNumber.

Regards

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable

Re: Count distinct is not working in script?

It seems not a calculation issue.

Better you put some of your sample data and sample output you want from that, it'll describe the problem in a better way.

Not applicable

Re: Count distinct is not working in script?

Manideep HV, Jonathan Delpino Awlad Hossain, I have attached the example document with explanation why I need to in this way.

Kindly assist.

Thanks and best regards,

Chanel

MVP
MVP

Re: Count distinct is not working in script?

Hi,

Try this script and check

Data:

LOAD Cabin,

     DOW,

     [Flt Wk Dt],

     [Flt Dt],

     Fltno,

     Region,

     Route,

     DepIATA,

     DestIATA,

     DestIATA2,

     Origin,

     Destination,

     ASK,

     RPK

FROM

[..\1_Resources\Map\sampledata for QC troubleshooting.xlsx]

(ooxml, embedded labels, table is Sheet2);

FlightNumber:

Load Fltno,

  //count(Fltno) as FlightNumber

  (Count(distinct Fltno) * Count(distinct [Flt Dt])) as FlightNumber

resident Data

group by Fltno;

Regards,

Jagan.

Not applicable

Re: Re: Count distinct is not working in script?

Hi Jagan,

Thanks for fast response, one step closer now. but it still looks not working correctly as shown in attachment.

We should get 112 flights for KUL-SIN route, but we can see 12 and 14 in [number of flight] field.

Thanks and best regards,

Chanel

MVP
MVP

Re: Re: Count distinct is not working in script?

Hi,

Can you attach some sample data?

Regards,

Jagan.

Not applicable

Re: Re: Count distinct is not working in script?

Hi Jagan,

I have attached the sample data in last reply named as sampledata for QC troubleshooting.xlsx

Thanks and best regards,

chanel

MVP
MVP

Re: Count distinct is not working in script?

Hi,

We are doing Group by Flight Number, so you are getting 12 and 14, if you want 112 then you need do Group by using Route dim.

FlightNumber:

Load Route,

  //[Flt Dt],

  //count(Fltno) as FlightNumber

  (Count(distinct Fltno) * Count(distinct [Flt Dt])) as FlightNumber

resident Data

group by Route;

Regards,

Jagan.

Community Browser