Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
paolojolly
Creator
Creator

Sum of record for max date near selected date

Hi,

I need help in qliview document

In this document I have a reference date field.

DATE.png

When I change the value of this date field a pivot table must be updated
For Example: if I select 01/10/2016 as date, in pivot i need to show for each customer, for max date near the selected date the
count of record in which field W_PRZ_PROMO is <= W_PRZ_PUBBL

CAMPO.png

thanks a lot to everyone

1 Solution

Accepted Solutions
sunny_talwar

Try this out.

Script:

LOAD ANNO_RILEVAZIONE,

    C_AGENTE,

    AutoNumber(C_NEGOZIO&DATA_RILEVAZIONE) as Key2,

    C_ARTICOLO,

    C_CLIENTE,

    C_NEGOZIO,

    C_PROGR_NEGOZIO,

    C_SCHEDA_LIS_PUBBL,

    C_TIPO_RIL,

    DATA_RILEVAZIONE,

    W_NR_FACING,

    W_PRZ_PROMO,

    W_PRZ_PUBBL

FROM

[DATA.xls]

(biff, embedded labels, table is Sheet1$);

Straight Table

Dimension

C_NEGOZIO

Expression

FirstSortedValue(DISTINCT DATA_RILEVAZIONE, -$(v_GroupRil))

Count({<Key2 = {"=Aggr(NODISTINCT FirstSortedValue(DISTINCT DATA_RILEVAZIONE, -$(v_GroupRil)), C_NEGOZIO) = DATA_RILEVAZIONE"}>}C_NEGOZIO)

Capture.PNG

View solution in original post

8 Replies
sunny_talwar

Would you be able to share a qvw to play around with this?

Update: I see you attached the sample, would you be able to provide some details about your expected output?

paolojolly
Creator
Creator
Author

I need to have a pivot like this

   

CUSTOMERMAX RIL DATE < SELECTED DATECOUNT OF RECORD FOR MAX RIL DATE  IN WITCH W_PRZ_PROMO is <= W_PRZ_PUBBL
C0000004-00120/09/201612
C0000004-00220/09/201660
C0000005-00915/09/201631
C0000005-01226/09/201641
C0000005-01326/09/201620
C0000009-00126/09/201610
C0000009-00128/09/201635
C0000053-00128/09/201653
C0000102-00120/09/201660
C0000381-00119/09/201684
C0000381-00221/09/201683
C0000381-00320/09/201685
C0000381-00426/09/201678
C0000381-00626/09/201685
C0000381-00730/09/201685
C0000428-00128/09/201645
C0000428-00530/09/201615
C0000428-00630/09/20164
C0000443-00928/09/201654
C0001524-00121/09/2016

20

sunny_talwar

I am not sure I understand how you are coming with these numbers? Can you may be pick one customer and explain how you got 12 for may be C0000004-001

rupamjyotidas
Specialist
Specialist

Probably you need to use Aggr() to group the equation with W_PRZ_PUBBL or W_PRZ_PROMO.

Aggr(Sum(if(W_PRZ_PROMO<=W_PRZ_PUBBL,1)),C_NEGOZIO)

paolojolly
Creator
Creator
Author

Se for example file DATA2.xls.

For C0000004-001 I have two values in DATA_RILEVAZIONE: 20.09.2016 and 10.03.2016.

If in the reference date field I select 4/10/2016 in the pivot table I should consider records with DATA_RILEVAZIONE 03.10.2016 (the largest <= 04.10.2016)

and for these records i have to count how many W_PRZ_PROMO is <= W_PRZ_PUBBL. In this case 72

I tried to use in the pivot

sum(IF((DATA_RILEVAZIONE) =
  (
 
FirstSortedValue(distinct (DATA_RILEVAZIONE
), -(
$(v_GroupRil)
))
)
  AND W_PRZ_PROMO <= W_PRZ_PUBBL, 1))

where v_GroupRil    is

if(
 
makedate(
year(DATA_RILEVAZIONE),
Month(DATA_RILEVAZIONE),
day(DATA_RILEVAZIONE)
  )
  <=
makedate(
Year($(data_rif)),
Month($(data_rif)),
day($(data_rif))
)
,
 
DATA_RILEVAZIONE
)

but not function.

thanks for the support

sunny_talwar

Try this out.

Script:

LOAD ANNO_RILEVAZIONE,

    C_AGENTE,

    AutoNumber(C_NEGOZIO&DATA_RILEVAZIONE) as Key2,

    C_ARTICOLO,

    C_CLIENTE,

    C_NEGOZIO,

    C_PROGR_NEGOZIO,

    C_SCHEDA_LIS_PUBBL,

    C_TIPO_RIL,

    DATA_RILEVAZIONE,

    W_NR_FACING,

    W_PRZ_PROMO,

    W_PRZ_PUBBL

FROM

[DATA.xls]

(biff, embedded labels, table is Sheet1$);

Straight Table

Dimension

C_NEGOZIO

Expression

FirstSortedValue(DISTINCT DATA_RILEVAZIONE, -$(v_GroupRil))

Count({<Key2 = {"=Aggr(NODISTINCT FirstSortedValue(DISTINCT DATA_RILEVAZIONE, -$(v_GroupRil)), C_NEGOZIO) = DATA_RILEVAZIONE"}>}C_NEGOZIO)

Capture.PNG

paolojolly
Creator
Creator
Author

Thanks so much.

It is what I need

sunny_talwar

Awesome

I am glad I was able to help.

Best,

Sunny