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

Announcements
Solving the Informatica Dilemma: On-Demand Briefing - Watch On Demand!
cancel
Showing results for 
Search instead for 
Did you mean: 
goncalo_ricardo_pereira
Partner - Contributor III
Partner - Contributor III

Help to create an expression

Hello all,

I really need your help to create one expression...

I am trying to create an expression that counts the number of periods where the materials have a value equal to 0.

Example of the records in my fact table (As you all can see, my fact table only has the records of each material that are not equal to 0. The Master Calendar connected to my fact table that have all the days between the min date until the max date available in the application):

MaterialDateValue
B01/05/201553
B02/05/201535
B03/05/20155
B04/05/201513
B05/05/2015357
B06/05/20153146
B07/05/201534
A08/05/2015734
A09/05/2015374
A10/05/201557
A11/05/20152346
A12/05/20157
A13/05/20157345
A14/05/201528
A15/05/2015257
A16/05/201524
A17/05/20152
A18/05/2015257
A19/05/2015956
A20/05/20156723
A21/05/2015257
A22/05/2015752
A23/05/2015234
A24/05/201554
A25/05/2015727
A26/05/2015226
A27/05/2015457
A28/05/201526
B29/05/201534
B30/05/2015754
B31/05/201523

Table with the final result of the expressions:

MaterialPeriods=0
A2
B1

Periods of each Material:

A -> First Period: 01/05/2015 - 07/05/2015

       Second Period: 29/05/2015 - 31/05/2015

Total of Periods with value equal to 0 for material A is: 2

B -> First Period: 08/05/2015 - 28/05/2015

Total of Periods with value equal to 0 for material B is: 1

Anyone has any idea how can I do this expression?

Best Regards.

Gonçalo Pereira

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Attached is a chart based solution, sensitive to filter.

View solution in original post

6 Replies
sunny_talwar

Would you be able to share a sample where you have loaded in this dummy data with the calendar table??

goncalo_ricardo_pereira
Partner - Contributor III
Partner - Contributor III
Author

Hello Sunindia,

Here is the sample qvw with the dummy data.

Best Regards.

Gonçalo Pereira

swuehl
MVP
MVP

Maybe like this:

SET DateFormat='DD/MM/YYYY';

INPUT:

LOAD Material,

    Date,

    Value

FROM

[https://community.qlik.com/thread/168723]

(html, codepage is 1252, embedded labels, table is @1);

Calendar:

LOAD Date(MinDate+iterno()) as Date

While MinDate+iterno() <= MaxDate;

LOAD max(FieldValue('Date',recno())) as MaxDate,

  min(FieldValue('Date',recno()))-1 as MinDate

AutoGenerate FieldValueCount('Date');

Let vMinDate = num(Peek('Date',0,'Calendar'));

Let vMaxDate = num(Peek('Date',-1,'Calendar'));

TEMP:

LOAD Material,

  Date,

  if(Peek(Material) <> Material, 1, rangesum(peek(Block), if(Date-peek(Date)>=2,1))) as Block

Resident INPUT

order by Material, Date asc;

LOAD Material,

  rangesum(max(Block),-1* (min(Date)>$(vMinDate)),-1*(max(Date)<$(vMaxDate)), -1) as NumPeriodsMissing

Resident TEMP

group by Material;

drop table TEMP;

goncalo_ricardo_pereira
Partner - Contributor III
Partner - Contributor III
Author

Hello swuehl,

Tks for your help, but is impossible to me to replicate this option in my application. In the real data we have to many dimension (not only the material), so basically the periods may change according to the filters applied by the user.

Basically, I need to create some of the script logic into an expression...

Best Regards

Gonçalo Pereira

swuehl
MVP
MVP

Attached is a chart based solution, sensitive to filter.

goncalo_ricardo_pereira
Partner - Contributor III
Partner - Contributor III
Author

Hello swuehl,

Tks for your help...

I actually believe that that your expression is the answer... so basically, I am now trying to adapt that expression to my reality.

Best Regards

Gonçalo Pereira