Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers!
Enter the sweepstakes now!Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.
Hi guys, How are you?
I tried to optimize my code to eliminate problems with many requests when trying to extract my records, I feel like it has improved, but the error still occurs. I noticed that the caching part in the first step doesn't work.
The following message is displayed on the screen:
How could I adjust this?
let
// Set global variable to store data cache
_cacheDados = if not Table.IsEmpty(_cacheDados) then _cacheDados else #table({}, {}),
// Function to make the API call with data cache
ObterDadosComCache = (page as number) =>
let
// Check if the data is already in the cache
dadosCache = Table.SelectRows(_cacheDados, each [page] = page),
// If not in the cache, make the API call
dados = if Table.IsEmpty(dadosCache) then ObterDadosDaAPI(page) else dadosCache
in
dados,
// Function to make the API call
ObterDadosDaAPI = (page as number) =>
let
// Increment the request counter
contadorAtualizado = contadorRequisicoes + 1,
// Call the API with the updated counter
Fonte = Json.Document(
Web.Contents(
"https://company.cvcrm.com.br/",
[
RelativePath = "api/v1/cvdw/repasses",
Query = [
registros_por_pagina = "1000",
a_partir_data_cad = "2023-01-01",
pagina = Number.ToText(page)
],
Headers = [
accept = "application/json",
email = _email,
token = _token
]
]
)
),
// Update the global counter
_ = contadorRequisicoes = contadorAtualizado
in
Fonte,
// Function call with the desired page
page = 1,
dados = ObterDadosComCache(page),
totalpages = fx_repasses(1)[total_de_paginas],
listOfPages = List.Generate(
() => [page = 1, data = fx_repasses(1)],
each [page] <= totalpages,
each [page = [page] + 1, data = fx_repasses([page]+1)]
),
//Transform data
#"Converted to Table" = Table.FromList(listOfPages, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Column1 Expandido" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"data"}, {"data"}),
#"data Expandido" = Table.ExpandRecordColumn(#"Column1 Expandido", "data", {"dados"}, {"dados"}),
#"dados Expandido" = Table.ExpandListColumn(#"data Expandido", "dados"),
#"dados Expandido1" = Table.ExpandRecordColumn(#"dados Expandido", "dados", {"numero", "situacao", "idreserva", "idempreendimento", "empreendimento", "unidade", "documento_cliente", "cliente", "data_assinatura_de_contrato", "data_cadastro"}, {"numero", "situacao", "idreserva", "idempreendimento", "empreendimento", "unidade", "documento_cliente", "cliente", "data_assinatura_de_contrato", "data_cadastro"}),
#"Personalização Adicionada" = Table.AddColumn(#"dados Expandido1", "Sistema", each "CV"),
#"Primeiros caracteres extraídos" = Table.TransformColumns(#"Personalização Adicionada", {{"data_cadastro", each Text.Start(_, 10), type text}}),
#"Colocar Cada Palavra Em Maiúscula" = Table.TransformColumns(#"Primeiros caracteres extraídos",{{"situacao", Text.Proper, type text}, {"empreendimento", Text.Proper, type text},{"cliente", Text.Proper, type text} }),
#"Tipo Alterado2" = Table.TransformColumnTypes(#"Colocar Cada Palavra Em Maiúscula",{{"numero", type text}, {"situacao", type text}, {"idreserva", type text}, {"empreendimento", type text}, {"unidade", type text}, {"documento_cliente", type text}, {"cliente", type text}, {"data_assinatura_de_contrato", type date}, {"data_cadastro", type date}, {"idempreendimento", type text}, {"Sistema", type text}}),
#"Linhas Filtradas" = Table.SelectRows(#"Tipo Alterado2", each
not Text.Contains([cliente], "Teste") or
not Text.Contains([cliente], "teste") or
not Text.Contains([cliente], "TESTE") or
not Text.Contains([empreendimento], "Teste") or
not Text.Contains([empreendimento], "teste") or
not Text.Contains([empreendimento], "TESTE") or
not Text.StartsWith([empreendimento], "40")
),
#"Consultas Mescladas" = Table.NestedJoin(#"Linhas Filtradas", {"numero"}, confirmação_vendas, {"Repasse"}, "confirmação_vendas", JoinKind.LeftOuter),
#"confirmação_vendas Expandido" = Table.ExpandTableColumn(#"Consultas Mescladas", "confirmação_vendas", {"Data do contrato(Nay)"}, {"Data do contrato(Nay)"}),
#"Consultas Mescladas2" = Table.NestedJoin(#"confirmação_vendas Expandido", {"numero"}, _historico_repasses, {"idrepasse"}, "_historico_situacoes", JoinKind.LeftOuter),
#"_historico_situacoes Expandido" = Table.ExpandTableColumn(#"Consultas Mescladas2", "_historico_situacoes", {"Data 1 Situacao repasse"}, {"Data 1 Situacao repasse"}),
#"Consultas Mescladas4" = Table.NestedJoin(#"_historico_situacoes Expandido", {"numero"}, _historico_distratos_repasses, {"idrepasse"}, "_historico_distratos_repasses", JoinKind.LeftOuter),
#"_historico_distratos_repasses Expandido" = Table.ExpandTableColumn(#"Consultas Mescladas4", "_historico_distratos_repasses", {"Data Cancelamento"}, {"Data Cancelamento"}),
#"Consultas Mescladas3" = Table.NestedJoin(#"_historico_distratos_repasses Expandido", {"idreserva"}, _ccvs, {"idreserva"}, "_ccvs", JoinKind.LeftOuter),
#"_ccvs Expandido" = Table.ExpandTableColumn(#"Consultas Mescladas3", "_ccvs", {"situacao", "idcorretor"}, {"situacao.1", "idcorretor"}),
#"Colunas Renomeadas1" = Table.RenameColumns(#"_ccvs Expandido",{{"data_assinatura_de_contrato", "assinatura"}}),
#"Coluna Condicional Adicionada2" = Table.AddColumn(#"Colunas Renomeadas1", "data_assinatura_de_contrato", each if [#"Data do contrato(Nay)"] <> null then [#"Data do contrato(Nay)"] else [assinatura]),
#"Colunas Renomeadas" = Table.RenameColumns(#"Coluna Condicional Adicionada2",{{"situacao.1", "Situação da Reserva"}}),
#"Coluna Condicional Adicionada1" = Table.AddColumn(#"Colunas Renomeadas", "Situacao resumida", each
if [data_assinatura_de_contrato] = null and [situacao] = "Repassado Com Pendência" and [Situação da Reserva] = "Contrato aprovado no Sienge" then "Sem data no sistema"
else if [data_assinatura_de_contrato] = null and [situacao] = "Venda Direta" and [Situação da Reserva] = "Contrato aprovado no Sienge" then "Sem data no sistema"
else if [data_assinatura_de_contrato] = null and [situacao] = "Repasse Confirmado" and [Situação da Reserva] = "Contrato aprovado no Sienge" then "Sem data no sistema"
else if [data_assinatura_de_contrato] = null and [situacao] = "Revalidação De Repasse" and [Situação da Reserva] = "Contrato aprovado no Sienge" then "Sem data no sistema"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Repassado Com Pendência" and [Situação da Reserva] = "Contrato aprovado no Sienge" then "Atualizados em sistema"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Venda Direta" and [Situação da Reserva] = "Contrato aprovado no Sienge" then "Atualizados em sistema"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Repasse Confirmado" and [Situação da Reserva] = "Contrato aprovado no Sienge" then "Atualizados em sistema"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Revalidação De Repasse" and [Situação da Reserva] = "Contrato aprovado no Sienge" then "Atualizados em sistema"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Ccv Com Pendência" then "Atualização de Status Pendente"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Cessão" then "Atualização de Status Pendente"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Contrato Com Pendência" then "Atualização de Status Pendente"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Aprovado Cehop (Ccv Com Pendência)" then "Atualização de Status Pendente"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Em Análise Cehop (Ccv Com Pendência)" then "Atualização de Status Pendente"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Aguardando Debito Fgts" then "Atualização de Status Pendente"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Aprovado Cehop" then "Atualização de Status Pendente"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Aguardando Débito Fgts (Ccv Com Pendência)" then "Atualização de Status Pendente"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Contrato Em Validação (Ccv Com Pendência)" then "Atualização de Status Pendente"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Em Análise Cehop" then "Atualização de Status Pendente"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Ccv Validado" then "Atualização de Status Pendente"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Revalidação De Contrato" then "Atualização de Status Pendente"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Ccv Em Validação" then "Atualização de Status Pendente"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Contrato Aprovado Sienge" then "Atualização de Status Pendente"
else if [data_assinatura_de_contrato] <> null and [situacao] = "Contrato Em Validação" then "Atualização de Status Pendente"
else null),
#"Coluna Condicional Adicionada" = Table.AddColumn(#"Coluna Condicional Adicionada1", "Data a contabilizar",
each if [data_assinatura_de_contrato] = null and [#"Data do contrato(Nay)"] <> null then [#"Data do contrato(Nay)"]
else if [data_assinatura_de_contrato] = null and [Data 1 Situacao repasse] <> null then [Data 1 Situacao repasse]
else [data_assinatura_de_contrato]),
#"Linhas Filtradas2" = Table.SelectRows(#"Coluna Condicional Adicionada", each [Data a contabilizar] > #date(2022, 12, 31) or [Data a contabilizar] = null),
#"Tipo Alterado1" = Table.TransformColumnTypes(#"Linhas Filtradas2",{{"Data a contabilizar", type date}, {"Situacao resumida", type text}, {"data_assinatura_de_contrato", type date}}),
#"Linhas Classificadas" = Table.Sort(#"Tipo Alterado1",{{"numero", Order.Ascending}}),
#"Duplicatas Removidas" = Table.Distinct(#"Linhas Classificadas", {"numero"}),
#"Colunas Removidas" = Table.RemoveColumns(#"Duplicatas Removidas",{ "Data do contrato(Nay)", "Data 1 Situacao repasse"}),
#"Consulta Acrescentada" = Table.Combine({#"Colunas Removidas", _sales_repasses})
in
#"Consulta Acrescentada"
Solved! Go to Solution.
Hi @kasife ,
The error message you're seeing, "IMPORT_CACHEDATA does not match any of the exports, are you missing any module references?" is a common error message in Power BI when there is a mismatch between the names of the functions in your code and the names of the functions in the Power Query Editor.
To resolve this error, you can try renaming the function in your code to match the name of the function in the Power Query Editor. For example, if the function in your code is named "ObterDadosComCache", you can try renaming it to "IMPORT_CACHEDATA" to match the name of the function in the Power Query Editor.
You can refer to the similar posts that may be helpful to you:
Expression.Error: The import [custom function] mat... - Microsoft Fabric Community
Expression.Error: The import xxxx matches no expor... - Microsoft Fabric Community
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @kasife ,
The error message you're seeing, "IMPORT_CACHEDATA does not match any of the exports, are you missing any module references?" is a common error message in Power BI when there is a mismatch between the names of the functions in your code and the names of the functions in the Power Query Editor.
To resolve this error, you can try renaming the function in your code to match the name of the function in the Power Query Editor. For example, if the function in your code is named "ObterDadosComCache", you can try renaming it to "IMPORT_CACHEDATA" to match the name of the function in the Power Query Editor.
You can refer to the similar posts that may be helpful to you:
Expression.Error: The import [custom function] mat... - Microsoft Fabric Community
Expression.Error: The import xxxx matches no expor... - Microsoft Fabric Community
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
User | Count |
---|---|
81 | |
71 | |
71 | |
56 | |
50 |
User | Count |
---|---|
43 | |
41 | |
37 | |
34 | |
30 |