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 / 1779078
Accepted
User1974
User1974
Asked: 2023-04-15 14:38:25 +0800 CST2023-04-15 14:38:25 +0800 CST 2023-04-15 14:38:25 +0800 CST

Atribuir ID de grupo a linhas (tags)

  • 772

Eu tenho uma tabela do Excel 365 de entradas de log. Os logs são agrupados por uma marca inicial e uma marca final.

insira a descrição da imagem aqui

Column C: =IF(   LEFT([@LOGS],6)="<Event","start",   IF(LEFT([@LOGS],7)="</Event","end",   ""))

Dados não tratados:

TAG_START_END   LOGS
start           <Event time="Sat Apr 15 1:13:17.750" type="Debug" thread="2fec: Main CIM worker thread" elapsed="0"
                Database: C:\2023 Files\GDBs_4\New Mobile Geodatabase.geodatabase
                      SQL: SELECT main.ACTIVE_TRANSPORTATION.OBJECTID,main.active_transportation_nt_flag_vw.flag FRO
end             </Event>
start           <Event time="Sat Apr 15 1:13:17.749" type="Debug" thread="2fec: Main CIM worker thread" elapsed="1"

end             </Event>
start           <Event time="Sat Apr 15 1:13:17.749" type="Debug" thread="2fec: Main CIM worker thread" elapsed="2"
                Database: C:\2023 Files\GDBs_4\New Mobile Geodatabase.geodatabase
                      SQL: SELECT main.ACTIVE_TRANSPORTATION.OBJECTID,main.active_transportation_nt_flag_vw.flag FRO
                      Number of features returned: 100
end             </Event>
start           <Event time="Sat Apr 15 1:13:17.749" type="Debug" thread="2fec: Main CIM worker thread" elapsed="0"

end             </Event>
start           <Event time="Sat Apr 15 1:13:17.747" type="Debug" thread="2fec: Main CIM worker thread" elapsed="0"
                Database: C:\2023 Files\GDBs_4\New Mobile Geodatabase.geodatabase
                      SQL: SELECT main.ACTIVE_TRANSPORTATION.OBJECTID,main.active_transportation_nt_flag_vw.flag FRO
end             </Event>
start           <Event time="Sat Apr 15 1:13:17.747" type="Debug" thread="2fec: Main CIM worker thread" elapsed="2"
                Database: C:\2023 Files\GDBs_4\New Mobile Geodatabase.geodatabase
                      SQL: SELECT main.ACTIVE_TRANSPORTATION.OBJECTID,main.active_transportation_nt_flag_vw.flag FRO
                      Number of features returned: 100
end             </Event>
start           <Event time="Sat Apr 15 1:13:17.746" type="Debug" thread="2fec: Main CIM worker thread" elapsed="1"

end             </Event>
start           <Event time="Sat Apr 15 1:13:17.746" type="Debug" thread="2fec: Main CIM worker thread" elapsed="0"

end             </Event>
start           <Event time="Sat Apr 15 1:13:17.744" type="Debug" thread="2fec: Main CIM worker thread" elapsed="0"
                Database: C:\2023 Files\GDBs_4\New Mobile Geodatabase.geodatabase
                      SQL: SELECT main.ACTIVE_TRANSPORTATION.OBJECTID,main.active_transportation_nt_flag_vw.flag FRO
end             </Event>
start           <Event time="Sat Apr 15 1:13:17.743" type="Debug" thread="2fec: Main CIM worker thread" elapsed="1"

end             </Event>

Para cada grupo de tags, desejo preencher a coluna GROUP_ID.

Na captura de tela acima, digitei manualmente os valores nesse campo. Agora, quero encontrar uma maneira de preencher o campo usando uma fórmula ou Power Query.


Como posso preencher a coluna GROUP_ID?

Motivo: quero eventualmente encontrar uma maneira de dinamizar as informações de LOGS em colunas: https://isstatic.askoverflow.dev/EfTUV.png . Acho que uma coluna GROUP_ID ajudaria com isso.


Relacionado:

Copie os logs do Diagnostic Monitor como tabela do Excel, não como tags verticais


Editar:

É assim que pode ser feito usando SQL:

Oracle SQL - Atribuir GROUP_ID a linhas com base nas tags de início/fim

sum(case when log_tags like '<Event%' then 1 else 0 end) over (order by id)

Algo semelhante pode ser feito no Excel?

microsoft-excel
  • 1 1 respostas
  • 45 Views

1 respostas

  • Voted
  1. Best Answer
    Frédéric Loyer
    2023-04-17T15:42:54+08:002023-04-17T15:42:54+08:00

    Com o PowerQuery, você pode definir AddGroupetapas AddSeqque se referenciam a si mesmas se o resultado estiver bem definido. Essas definições recursivas precisam de um @no nome de cada etapa ao fazer referência a elas.

    let
        Source = Excel.CurrentWorkbook(){[Name="Table"]}[Content],
        TypeChanged = Table.TransformColumnTypes(Source,{{"TAG_START_END", type text}, {"LOGS", type text}}),
        IndexAdded = Table.AddIndexColumn(TypeChanged, "Index", 0, 1),
        AddSeq = Table.AddColumn(IndexAdded, "Seq", 
           each if [TAG_START_END]="start" then 1 else @AddSeq[Seq]{[Index]-1} +1),
        AddGroup = Table.AddColumn(AddSeq, "GroupID", 
           each if [TAG_START_END]="start" 
                then (if [Index]=0 then 1 else @AddGroup[GroupID]{[Index]-1}+1) 
                else @AddGroup[GroupID]{[Index]-1})
    in
        AddGroup
    

    Aqui IndexAdded insere uma coluna de índice necessária para referenciar a tabela uma célula acima ( {[Index]-1})

    Aqui, usei a coluna C (início/fim), mas Text.StartsWithpoderia ser usada para calcular a condição inicial no PowerQuery.

    O script pode ser aprimorado para reordenar as colunas ou suprimir a coluna de índice.


    Esta consulta é fácil de escrever (se soubermos sobre construção recursiva de uma tabela), mas não muito eficiente.

    Aqui está uma nova versão otimizada (3s para 2.000 linhas). Leva diretamente uma LOGScoluna, verifique se começa com <Event, se sim, inicie uma nova sequência de grupo.

    let
        Source = Excel.CurrentWorkbook(){[Name="Table"]}[Content],
        TypeChanged = Table.TransformColumnTypes(Source,{{"LOGS", type text}}),
        Lines = Table.ToRecords(TypeChanged),
        Result = List.Accumulate(Lines, [table={}, group=0, seq=0],
            (state, current) => if Text.StartsWith(current[LOGS],"<Event")
                then let g = state[group]+1, s = 1 in
                     [ table= state[table] & {[group=g,seq=s] & current},
                       group=g, seq=s] 
                else let g = state[group], s = state[seq]+1 in
                     [ table= state[table] & {[group=g,seq=s] & current},
                       group=g, seq=s] ),
        Table1 = Result[table],
        Table2 = Table.FromRecords(Table1)
    in
        Table2
    
    • 3

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