-
Notifications
You must be signed in to change notification settings - Fork 7
/
IdentificaTipoDadosCadaColunaTabela.txt
80 lines (67 loc) · 3.08 KB
/
IdentificaTipoDadosCadaColunaTabela.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
let
funcao =
// ====================================== COMEÇA FUNÇÃO ======================================
(
Tabela as table,
optional SomenteTipos as list,
optional ExcetoTipos as list
) =>
let
PrimeiraLinhaTabela = Table.FirstN(Tabela,1),
Despivotar = Table.UnpivotOtherColumns(PrimeiraLinhaTabela, {}, "Atributo", "Valor"),
ExtraindoTipoDado = Table.TransformColumns(Despivotar, {{"Valor", each Value.Type(_), type text}}),
Filtrar = Table.SelectRows(ExtraindoTipoDado, each
if SomenteTipos = null and ExcetoTipos = null then true
else if SomenteTipos <> null then List.Contains((if SomenteTipos = null then {} else SomenteTipos), [Valor])
else not List.Contains((if ExcetoTipos = null then {} else ExcetoTipos), [Valor])
)
in
Filtrar
// ====================================== COMEÇA FUNÇÃO ======================================
, metadados = [
Documentation.Name = "IdentificaTipoDadosCadaColunaTabela",
Documentation.Description = "by Joviano Silveira (www.joviano.com) => Função identifica e (se quiser) filtra os tipos de dados de uma tabela",
Documentation.Examples = {
// exemplo 01
[
Description = "Tipos de dados de uma tabela",
Code = "IdentificaTipoDadosCadaColunaTabela(Tabela)",
Result = "
{
{ColunaA, type number},
{ColunaB, type text},
{ColunaC, type Int64.Type}
}
"
],
// exemplo 02
[
Description = "Tipos de dados de uma tabela, e filtrar somente tipos texto",
Code = "IdentificaTipoDadosCadaColunaTabela(Tabela, {type text}, null)",
Result = "
{
{ColunaB, type text}
}
obs: se informar o parametro 'SomenteTipo' o 'ExcetoTipo' não será lido, e vice versa
"
],
// exemplo 02
[
Description = "Tipos de dados de uma tabela, e filtrar exceto tipos texto",
Code = "IdentificaTipoDadosCadaColunaTabela(Tabela, null, {type text})",
Result = "
{
{ColunaA, type number},
{ColunaC, type Int64.Type}
}
"
]
}
]
in
Value.ReplaceType(
funcao,
Value.ReplaceMetadata(
Value.Type(funcao),metadados
)
)