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

Criar AgeRange dentro de uma planilha

Prezados, boa tarde.

Estou tentando criar um Age Range conforme o GIF abaixo mas sem sucesso. Alguém consegue me ajudar?

AGE RANGE NÃO FUNCIONA.gif

Labels (2)
1 Solution

Accepted Solutions
Thiago_Justen_

Ayrton,

Faça como segue:

[Planilha1]:

LOAD

  [NUMERO],

[MUNICIPIO],

[DISTRITO],

[BAIRRO],

[CRIME],

[DATA],

    Year(DATA)  AS [Ano Ocorrência],

    Month(DATA) AS [Mês Ocorrência],

    WeekDay(DATA) AS [Dia Semana Ocorrência],

    [NASCIMENTO],

    Age(Today(1),[NASCIMENTO]) As [IDADE],

   If(Age(Today(1),[NASCIMENTO]) <=17, '<17 Anos',

  IF(Age(Today(1),[NASCIMENTO]) >= 17 and Age(Today(1),[NASCIMENTO]) < 25, '17 - 25',

  IF(Age(Today(1),[NASCIMENTO])>= 25 and Age(Today(1),[NASCIMENTO])< 30, '25 - 30',

  IF(Age(Today(1),[NASCIMENTO]) >= 30 and [Age(Today(1),[NASCIMENTO]) < 40, '30 - 40',

  IF(Age(Today(1),[NASCIMENTO])>= 40 and Age(Today(1),[NASCIMENTO])< 50, '40 - 50',

  '50+'))))) as [AgeRange]

        FROM [lib://QLIK APP SEGURANÇA/DADOSASSALTOS.xlsx]

(ooxml, embedded labels, table is Planilha1);

Ou ainda

[Planilha1]:

LOAD

  [NUMERO],

[MUNICIPIO],

[DISTRITO],

[BAIRRO],

[CRIME],

[DATA],

    Year(DATA)  AS [Ano Ocorrência],

    Month(DATA) AS [Mês Ocorrência],

    WeekDay(DATA) AS [Dia Semana Ocorrência],

    [NASCIMENTO],

    Age(Today(1),[NASCIMENTO]) As [IDADE],

If(Peek([IDADE])<=17, '<17 Anos',

  IF(Peek([IDADE])>= 17 and Peek([IDADE])< 25, '17 - 25',

  IF(Peek([IDADE])>= 25 and [Peek([IDADE])< 30, '25 - 30',

  IF(Peek([IDADE])>= 30 and Peek([IDADE])< 40, '30 - 40',

  IF(Peek([IDADE]) >= 40 and Peek([IDADE]) < 50, '40 - 50',

  '50+'))))) as [AgeRange]

        FROM [lib://QLIK APP SEGURANÇA/DADOSASSALTOS.xlsx]

(ooxml, embedded labels, table is Planilha1);

Thiago Justen Teixeira Gonçalves
Farol BI
WhatsApp: 24 98152-1675
Skype: justen.thiago

View solution in original post

5 Replies
Thiago_Justen_

Ayrton,

O campo IDADE está sendo "criado" no mesmo bloco do seu AgeRange...no bloco if onde você cria o AgeRange substitua IDADE por NASCIMENTO.

Isso resolverá.

Abs e Sucesso!!

Thiago Justen Teixeira Gonçalves
Farol BI
WhatsApp: 24 98152-1675
Skype: justen.thiago
Anonymous
Not applicable
Author

Eu já tinha tentado fazer desta forma mas ele retorna todas as linhas como 50+.

Consegui realizar a solução da seguinte forma:

_____________________________

[Planilha1]:

LOAD *,

       If([IDADE] <=17, '<17 Anos',

  IF([IDADE] >= 17 and [IDADE] < 25, '17 - 25',

  IF([IDADE] >= 25 and [IDADE] < 30, '25 - 30',

  IF([IDADE] >= 30 and [IDADE] < 40, '30 - 40',

  IF([IDADE] >= 40 and [IDADE] < 50, '40 - 50',

  '50+'))))) as [AgeRange];

 

LOAD

  [NUMERO],

[MUNICIPIO],

[DISTRITO],

[BAIRRO],

[CRIME],

[DATA],

    Year(DATA)  AS [Ano Ocorrência],

    Month(DATA) AS [Mês Ocorrência],

    WeekDay(DATA) AS [Dia Semana Ocorrência],

    [NASCIMENTO],

    Age(Today(1),[NASCIMENTO]) As [IDADE]

        FROM [lib://QLIK APP SEGURANÇA/DADOSASSALTOS.xlsx]

(ooxml, embedded labels, table is Planilha1);

___________________________________________

Eu gostaria de jogar esse LOAD com função IF para logo após [IDADE], assim quando fosse visto pelo visualizador de modelo de dados ficaria correta a ordenação de campos.

Thiago_Justen_

Ayrton,

Faça como segue:

[Planilha1]:

LOAD

  [NUMERO],

[MUNICIPIO],

[DISTRITO],

[BAIRRO],

[CRIME],

[DATA],

    Year(DATA)  AS [Ano Ocorrência],

    Month(DATA) AS [Mês Ocorrência],

    WeekDay(DATA) AS [Dia Semana Ocorrência],

    [NASCIMENTO],

    Age(Today(1),[NASCIMENTO]) As [IDADE],

   If(Age(Today(1),[NASCIMENTO]) <=17, '<17 Anos',

  IF(Age(Today(1),[NASCIMENTO]) >= 17 and Age(Today(1),[NASCIMENTO]) < 25, '17 - 25',

  IF(Age(Today(1),[NASCIMENTO])>= 25 and Age(Today(1),[NASCIMENTO])< 30, '25 - 30',

  IF(Age(Today(1),[NASCIMENTO]) >= 30 and [Age(Today(1),[NASCIMENTO]) < 40, '30 - 40',

  IF(Age(Today(1),[NASCIMENTO])>= 40 and Age(Today(1),[NASCIMENTO])< 50, '40 - 50',

  '50+'))))) as [AgeRange]

        FROM [lib://QLIK APP SEGURANÇA/DADOSASSALTOS.xlsx]

(ooxml, embedded labels, table is Planilha1);

Ou ainda

[Planilha1]:

LOAD

  [NUMERO],

[MUNICIPIO],

[DISTRITO],

[BAIRRO],

[CRIME],

[DATA],

    Year(DATA)  AS [Ano Ocorrência],

    Month(DATA) AS [Mês Ocorrência],

    WeekDay(DATA) AS [Dia Semana Ocorrência],

    [NASCIMENTO],

    Age(Today(1),[NASCIMENTO]) As [IDADE],

If(Peek([IDADE])<=17, '<17 Anos',

  IF(Peek([IDADE])>= 17 and Peek([IDADE])< 25, '17 - 25',

  IF(Peek([IDADE])>= 25 and [Peek([IDADE])< 30, '25 - 30',

  IF(Peek([IDADE])>= 30 and Peek([IDADE])< 40, '30 - 40',

  IF(Peek([IDADE]) >= 40 and Peek([IDADE]) < 50, '40 - 50',

  '50+'))))) as [AgeRange]

        FROM [lib://QLIK APP SEGURANÇA/DADOSASSALTOS.xlsx]

(ooxml, embedded labels, table is Planilha1);

Thiago Justen Teixeira Gonçalves
Farol BI
WhatsApp: 24 98152-1675
Skype: justen.thiago
danielabyt
Partner - Contributor II
Partner - Contributor II

Caro Ayrton,

Tente utilizar a função dual, segue exemplo:

if(fabs(idade)<18,Dual('<17 Anos',1),if(fabs(idade)<26,Dual('17 - 25',2)

,if(fabs(idade)<31,Dual('26 - 30',3),if(fabs(idade)<41,Dual('31 - 40',4),if(fabs(idade)<51,Dual('41 - 50',5),Dual('>50',6)))))) as RANGE

Caso não possua número  negativos, tire o fabs... Em se tratando de input de dados eu acredito que tudo pode acontecer rsss...

Anonymous
Not applicable
Author

Obrigado Thiago, as duas formas funcionaram.

Daniel, não cheguei a testar a sua pois nunca utilizei FABS, vou estudar mais e incluir esta função. Obrigado a você também.

Atenciosamente.