Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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_YEAR | DATE | SELL |
---|---|---|
16-32 | 01/08/2016 | 0 |
16-31 | 31/07/2016 | 1000 |
16-31 | 30/07/2016 | 500 |
16-31 | 29/07/2016 | 500 |
16-31 | 28/07/2016 | 600 |
16-31 | 27/07/2016 | 700 |
16-31 | 26/07/2016 | 100 |
16-31 | 25/07/2016 | 200 |
16-30 | 24/07/2016 | 300 |
16-30 | 23/07/2016 | 400 |
16-30 | 22/07/2016 | 500 |
16-30 | 21/07/2016 | 600 |
16-30 | 20/07/2016 | 400 |
16-30 | 19/07/2016 | 300 |
16-30 | 18/07/2016 | 400 |
16-30 | 17/07/2016 | 800 |
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.
SEMANA CORRENTE
=sum({<WEEK_YEAR={"$(=Replace( mid(WeekName(Today()),3),'/','-'))"} >} QTD)
SEMANA ANTERIOR
=sum({<WEEK_YEAR={"$(=Replace( mid(WeekName(Today()-7),3),'/','-'))"} >} QTD)
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)
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
DATA | SEMANA_ANO | WeekName (qlikView) |
2016-12-19 | 16-52 | 16-52 |
2016-12-20 | 16-52 | 16-52 |
2016-12-21 | 16-52 | 16-52 |
2016-12-22 | 16-52 | 16-52 |
2016-12-23 | 16-52 | 16-52 |
2016-12-24 | 16-52 | 16-52 |
2016-12-25 | 16-52 | 16-52 |
2016-12-26 | 17-01 | 16-53 |
2016-12-27 | 17-01 | 16-53 |
2016-12-28 | 17-01 | 16-53 |
2016-12-29 | 17-01 | 16-53 |
2016-12-30 | 17-01 | 16-53 |
2016-12-31 | 17-01 | 16-53 |
2017-01-01 | 17-01 | 17-01 |
2017-01-02 | 17-02 | 17-01 |
2017-01-03 | 17-02 | 17-01 |
2017-01-04 | 17-02 | 17-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,
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.
a data 01/01/2017 é o today? ou vc irá selecionar?
vc pode fazer pela data
data >= data-7 e data <= data
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é?
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
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)
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.