AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / computer / Perguntas / 1817431
Accepted
Dave
Dave
Asked: 2023-11-20 22:35:22 +0800 CST2023-11-20 22:35:22 +0800 CST 2023-11-20 22:35:22 +0800 CST

Power Query: Combine o subconjunto da lista de tabelas existentes

  • 772

Estou usando o Power Query no Excel para Microsoft 365.

Tenho um Power Query cujo primeiro passo é combinar um conjunto de tabelas:

let
    Source = Table.Combine({One_foo_bar, Two_foo_bar, Three_foo_bar, Four_foo_bar, Five_foo_bar, Six_foo_bar, Seven_foo_bar, Eight_foo_bar}),
    // ...
    #"Result" = ...
in
    #"Result"

O problema é que nem todas as tabelas nomeadas podem existir. Qualquer subconjunto das tabelas pode existir. Aqueles que existem estão em ThisWorkbook. Se algum estiver faltando, o código M mostrado acima gerará um erro.

Se a correspondência de padrões puder ajudar a resolver esse problema, todos os nomes das tabelas seguirão o padrão * _foo_bar . M não parece ter suporte para esse tipo de correspondência de padrões, mas incluo esta afirmação caso alguém saiba algo que não sei e possa utilizar esse fato para formular uma solução.

Como posso modificar este código para combinar as tabelas que existem?

microsoft-excel
  • 3 3 respostas
  • 66 Views

3 respostas

  • Voted
  1. gns100
    2023-11-21T00:39:42+08:002023-11-21T00:39:42+08:00

    Good question, and this is not a full answer, but I would start with this idea. First, build the array of existing tables in excel like:

    enter image description here

    then using power query to get the existing tables from that table.

    An alternative is to build that array more directly in PowerQuery using TRY

    • 1
  2. Best Answer
    DjC
    2023-11-21T09:00:46+08:002023-11-21T09:00:46+08:00

    Use Excel.CurrentWorkbook() as the Source, then filter the Name column to return only the items that end with "_foo_bar". For example,

    let
        Source = Excel.CurrentWorkbook(),
        #"Filtered Rows" = Table.SelectRows(Source, each Text.EndsWith([Name], "_foo_bar")),
        #"Combine Tables" = Table.Combine(#"Filtered Rows"[Content])
    in
        #"Combine Tables"
    
    • 1
  3. Dave
    2023-11-21T20:36:34+08:002023-11-21T20:36:34+08:00

    Although I have accepted the answer given by @DjC, I'll post for future reference an answer I arrived at using the suggestion given by @gns100.

    let
        remove_errors_f = (input_list as list) as list =>
                              List.RemoveNulls(
                                                  List.Transform(
                                                                    List.Positions(input_list),
                                                                    each try input_list{_} otherwise null
                                                                )
                                              ),
    
        #"MyTables" = remove_errors_f({One_foo_bar, Two_foo_bar, Three_foo_bar, Four_foo_bar, Five_foo_bar, Six_foo_bar, Seven_foo_bar, Eight_foo_bar}),
        #"Column Names" = {"Column1", "Column2", "Column3", "Column4"},
    
        combiner_f = (AccumulatedTable as table, TablesToCombine as list) as table =>
                     if List.Count(TablesToCombine) = 0 then
                         AccumulatedTable
                     else
                         @combiner_f(Table.Combine({AccumulatedTable, TablesToCombine{0}}), List.RemoveFirstN(TablesToCombine, 1)),
    
        Source = combiner_f(#table(#"Column Names", {}), #"MyTables"),
        // ...
        #"Result" = ...
    in
        #"Result"
    
    • 0

relate perguntas

  • Excel Pivot com operador "e"

  • Como usar a função LENGTH do Excel para uma coluna inteira?

  • Matriz do Excel (2 variáveis)

  • como abrir um arquivo de escritório do WSL

  • VBA para renomear planilha com base no nome do arquivo

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Como posso reduzir o consumo do processo `vmmem`?

    • 11 respostas
  • Marko Smith

    Baixar vídeo do Microsoft Stream

    • 4 respostas
  • Marko Smith

    O Google Chrome DevTools falhou ao analisar o SourceMap: chrome-extension

    • 6 respostas
  • Marko Smith

    O visualizador de fotos do Windows não pode ser executado porque não há memória suficiente?

    • 5 respostas
  • Marko Smith

    Como faço para ativar o WindowsXP agora que o suporte acabou?

    • 6 respostas
  • Marko Smith

    Área de trabalho remota congelando intermitentemente

    • 7 respostas
  • Marko Smith

    O que significa ter uma máscara de sub-rede /32?

    • 6 respostas
  • Marko Smith

    Ponteiro do mouse movendo-se nas teclas de seta pressionadas no Windows?

    • 1 respostas
  • Marko Smith

    O VirtualBox falha ao iniciar com VERR_NEM_VM_CREATE_FAILED

    • 8 respostas
  • Marko Smith

    Os aplicativos não aparecem nas configurações de privacidade da câmera e do microfone no MacBook

    • 5 respostas
  • Martin Hope
    Vickel O Firefox não permite mais colar no WhatsApp web? 2023-08-18 05:04:35 +0800 CST
  • Martin Hope
    Saaru Lindestøkke Por que os arquivos tar.xz são 15x menores ao usar a biblioteca tar do Python em comparação com o tar do macOS? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh Como posso reduzir o consumo do processo `vmmem`? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Pesquisa do Windows 10 não está carregando, mostrando janela em branco 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    andre_ss6 Área de trabalho remota congelando intermitentemente 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney Por que colocar um ponto após o URL remove as informações de login? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension Ponteiro do mouse movendo-se nas teclas de seta pressionadas no Windows? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca Todos os meus complementos do Firefox foram desativados repentinamente, como posso reativá-los? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK É possível criar um código QR usando texto? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 Altere o nome da ramificação padrão do git init 2019-04-01 06:16:56 +0800 CST

Hot tag

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve