Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Show on a label a value regarding the current week

Good afternoon , I have to make a report that shows on a label the sale of the current week and the other the sale of the previous week. But the week we use is not the same as Week, WeekName .. functions . I need something like this query .


Select semana_ano, sum(qtd) from tabela where semana_ano =  (select semana_ano from calendario where data = currentdate()).

Example:

WEEK_YEARDATESELL
16-3201/08/20160
16-3131/07/20161000
16-3130/07/2016500
16-3129/07/2016500
16-3128/07/2016600
16-3127/07/2016700
16-3126/07/2016100
16-3125/07/2016200
16-3024/07/2016300
16-3023/07/2016400
16-3022/07/2016500
16-3021/07/2016600
16-3020/07/2016400
16-3019/07/2016300
16-3018/07/2016400
16-3017/07/2016800

I need to create a label that has , for example.... IF TODAY IS 29/07, this label should add the SALES days 31,30,29,28,27,26,25 , ie all dates of the week 16-31 , which is the week regarding the day ( 29/07 ) .

In another label you must be the sale of the previous week , ie if today is 29/07 , week 16-31 , will show the sum of sales days regarding the week 16-30 ( last week )



Thanks a lot for the help.



Note: Title translated to English by Community Moderator as a courtesy.

10 Replies
Not applicable
Author

SEMANA CORRENTE

=sum({<WEEK_YEAR={"$(=Replace( mid(WeekName(Today()),3),'/','-'))"} >} QTD)

SEMANA ANTERIOR

=sum({<WEEK_YEAR={"$(=Replace( mid(WeekName(Today()-7),3),'/','-'))"} >} QTD)

Anonymous
Not applicable
Author

Hi

try this

=sum({<DATE={">=$(=date(TODAY()-7,'MM/DD/YYYY'))<=$(=date(TODAY(),'MM/DD/YYYY'))"}>} SELL)

and

=sum({<DATE={">=$(=date(TODAY()-12,'MM/DD/YYYY'))<$(=date(TODAY()-7,'MM/DD/YYYY'))"}>} SELL)

Not applicable
Author

Rodrigo, muito obrigado pelo retorno, porém utilizar o WeekName não é confiável, pois o calendário aqui é diferente do padrão do sistema. Aqui, por exemplo não existe a semana 53, sendo assim eu terei problema em dezembro e Janeiro onde:

DATA

DATASEMANA_ANOWeekName (qlikView)
2016-12-1916-5216-52
2016-12-2016-5216-52
2016-12-2116-5216-52
2016-12-2216-5216-52
2016-12-2316-5216-52
2016-12-2416-5216-52
2016-12-2516-5216-52
2016-12-2617-0116-53
2016-12-2717-0116-53
2016-12-2817-0116-53
2016-12-2917-0116-53
2016-12-3017-0116-53
2016-12-31   17-0116-53
2017-01-0117-0117-01
2017-01-0217-0217-01
2017-01-0317-0217-01
2017-01-0417-0217-01

      O que preciso é de uma função que retorne o campo SEMANA_ANO referente a uma data. Por exemplo, no dia 01/01/2017, preciso das vendas de 26/12/2016 até 01/01/2017 que corresponde a semana 17-01, se eu usar o WEEKNAME teria as vendas do período de 01/01/2017 até 08/01/2017, bem diferente.

Será que isso é possível?

Obrigado,

Not applicable
Author

Hi Alluraiah, tks so much,


But the period ​​must be based on WEEK_YEAR and DATE fields , we can not calculate the sale of 7 or 14 days ago.


Thank you for your help.

Not applicable
Author

a data 01/01/2017 é o today? ou vc irá selecionar?


vc pode fazer pela data


data >= data-7 e data <= data

Not applicable
Author

A DATA é TODAY. Inclusive terei que fazer a variação referente à semana anterior.

Pegando pela data funciona somente no ultimo dia da semana. Por exemplo, no dia 27/12, não podemos somar o período de 7 dias pra trás, somente o período referente à semana do dia, neste caso seria de pegar somente 26 e 27/12, que é referente a semana 2017-01.

Complicado né?

Not applicable
Author

Algo assim: Neste caso funciona se uma data estiver selecionada.

=Count({1<DATA={"<=$(=DATA)>=$(=date(DATA-6,'YYYY-MM-DD'))"}>} SEMANA_ANO)

para semana anterior mude a quantidade de dias

Not applicable
Author

entendi são períodos fechados

Neste caso use:

=Count({1<DATA={">=$(=date( WeekStart(Today()),'YYYY-MM-DD'))<=$(=date( WeekEnd(Today()),'YYYY-MM-DD'))"}>} SEMANA_ANO)



=Count({1<DATA={">$(=date( WeekStart(Today()-14),'YYYY-MM-DD'))<$(=date( WeekEnd(Today()-7),'YYYY-MM-DD'))"}>} SEMANA_ANO)



Not applicable
Author

Perfeito, só vou modificar o today para DATA e colocar um if (se não for selecionado nenhuma data ou semana, utilizar o Today).

Muito obrigado pela ajuda.