Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Count Null by Set Analysis

Hi Guys,

I am trying to count Null in expression and using the below statement. but did not get luck to resolve it. I tried couple of different way by set analysis. Could you please advise me about this?

=Count({$<Year=, Month=, Sale ={'=Len(Trim(Sale))=0'} , YearMonth={">=$(=Date(MonthStart(AddMonths(Min(SaleDate),0)),'YYYYMM'))<=$(=Date(MonthStart(AddMonths(Max(SaleDate),0)),'YYYYMM'))"}>} Sale)

Kind regards

Farrukh

1 Solution

Accepted Solutions
sunny_talwar

Try something like this:

=Count({$<Year=, Month=, UniqueIdenfierFieldHere = {"=Len(Trim(Sale))=0"} , YearMonth ={">=$(=Date(MonthStart(AddMonths(Min(SaleDate),0)),'YYYYMM'))<=$(=Date(MonthStart(AddMonths(Max(SaleDate),0)),'YYYYMM'))"}>} Sale)

Or you can create a flag in the script

LOAD Sale,

          If(Len(Trim(Sale)) = 0, 1, 0) as SaleFlag

...

and then use like this:

=Count({$<Year=, Month=, SaleFlag = {1}, YearMonth ={">=$(=Date(MonthStart(AddMonths(Min(SaleDate),0)),'YYYYMM'))<=$(=Date(MonthStart(AddMonths(Max(SaleDate),0)),'YYYYMM'))"}>} Sale)

View solution in original post

7 Replies
dineshm030
Creator III
Creator III

Can you provide the sample QVW file?

marcus_sommer

You could try something like this:

=Count({$<Sale -={'*'}>} Sale)

For testings without further conditions to simplify the approach and avoiding potential errors in other parts - and using from normal selections to reduce the amount of data respectively to emulate the conditions.

But are there really NULL's within the field Sale? If Sale is an field from a common transaction-table there will be quite probably just no records instead of records with NULL. To visualize NULL's is often quite complex - a very good starting point could you find here: NULL handling in QlikView.

- Marcus

sunny_talwar

Try something like this:

=Count({$<Year=, Month=, UniqueIdenfierFieldHere = {"=Len(Trim(Sale))=0"} , YearMonth ={">=$(=Date(MonthStart(AddMonths(Min(SaleDate),0)),'YYYYMM'))<=$(=Date(MonthStart(AddMonths(Max(SaleDate),0)),'YYYYMM'))"}>} Sale)

Or you can create a flag in the script

LOAD Sale,

          If(Len(Trim(Sale)) = 0, 1, 0) as SaleFlag

...

and then use like this:

=Count({$<Year=, Month=, SaleFlag = {1}, YearMonth ={">=$(=Date(MonthStart(AddMonths(Min(SaleDate),0)),'YYYYMM'))<=$(=Date(MonthStart(AddMonths(Max(SaleDate),0)),'YYYYMM'))"}>} Sale)

vinieme12
Champion III
Champion III

Try

=Count({$<Year=, Month=, Sale ={'=isnull(Sale)=-1'} , YearMonth={">=$(=Date(MonthStart(AddMonths(Min(SaleDate),0)),'YYYYMM'))<=$(=Date(MonthStart(AddMonths(Max(SaleDate),0)),'YYYYMM'))"}>} Sale)

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
Anonymous
Not applicable
Author

Hi Sunny,

Could you please advise me related to UniqueIdentifierField, I am using couple of dimensions, eg (MonthYear, Region, Company, Distrct). or do I need to use one of the dimension as an uniqueidentifierfield.

Farrukh

sunny_talwar

I am looking for a field which uniquely defines each row in your fact table? If you don't have any, you can create one using

LOAD RowNo() as UniqueIdentifier

Taking a step back, why are you trying to remove null sales from your Sum(Sale)? Sum(Sale) would never include any sales which are null? What is the goal here?

Anonymous
Not applicable
Author

Thanks Sunny,

Its sorted.

Farrukh