Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
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
jagan
Luminary Alumni
Luminary Alumni

Hi,

Try any of this expressions

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

or

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

Regards,

Jagan.

View solution in original post

12 Replies
manideep78
Partner - Specialist
Partner - Specialist

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.

jonathandienst
Partner - Champion III
Partner - Champion III

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
Author

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
Author

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

jagan
Luminary Alumni
Luminary Alumni

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
Author

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

jagan
Luminary Alumni
Luminary Alumni

Hi,

Can you attach some sample data?

Regards,

Jagan.

Not applicable
Author

Hi Jagan,

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

Thanks and best regards,

chanel

jagan
Luminary Alumni
Luminary Alumni

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.