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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Tabela com múltiplas ocorrências baseada em uma fórmula

Tenho uma tabela com as informações individuais de alguns colaboradores (TB_Colaboradores) e uma com treinamentos (TB_Treinamentos). Eu criei uma coluna que filtra os treinamentos que um colaborador deve fazer baseada em uma série de parâmetros:

 

 

Nº de Treinamentos = COUNTROWS(
FILTER(
    FILTER(
        ADDCOLUMNS(
            ADDCOLUMNS(
                FILTER(ALL(TB_Treinamentos),
                AND(IF(AND(NOT(ISBLANK(TB_Colaboradores[Última Modificação])),DATEDIFF(TODAY(),TB_Colaboradores[Última Modificação],DAY)>=-30),TB_Treinamentos[Início]<=TB_Colaboradores[Última Modificação],1=1),
                OR(TB_Treinamentos[Frequencia] = "NA",AND(TB_Treinamentos[Início] <= TODAY(),TB_Treinamentos[Fim] >= TODAY())))
                ),"ID_FÁBRICA",IF(ISBLANK(TB_Treinamentos[ID_Area]),LOOKUPVALUE(TB_Cargos[ID_Area],TB_Cargos[ID],TB_Treinamentos[ID_Cargo]),LOOKUPVALUE(TB_Areas[ID_Fabrica],TB_Areas[ID],TB_Treinamentos[ID_Area])),"CARGO",
                LOOKUPVALUE(TB_Cargos[Nome],TB_Cargos[ID],TB_Treinamentos[ID_Cargo]),"ID_AREA1",IF(ISBLANK(TB_Treinamentos[ID_Area]),LOOKUPVALUE(TB_Cargos[ID_Area],TB_Cargos[ID],TB_Treinamentos[ID_Cargo]),TB_Treinamentos[ID_Area])
            ),"AREA",LOOKUPVALUE(TB_Areas[Nome],TB_Areas[ID],[ID_AREA1])), 

        TB_Treinamentos[Nivel] = "Organização" && TB_Treinamentos[EspCargo] = FALSE() ||
        TB_Treinamentos[Nivel] = "Empresa" && TB_Treinamentos[Especificacao] = TB_Colaboradores[Empresa] ||
        TB_Treinamentos[Nivel] = "Fábrica" && TB_Treinamentos[Especificacao] = TB_Colaboradores[Fábrica] && TB_Treinamentos[EspCargo] = FALSE() ||
        TB_Treinamentos[Nivel] = "Área" && TB_Treinamentos[Especificacao] = TB_Colaboradores[Area] && TB_Treinamentos[EspCargo] = FALSE() && TB_Treinamentos[TipoCargo] = "Organização" ||
        TB_Treinamentos[Nivel] = "Área" && TB_Treinamentos[Especificacao] = TB_Colaboradores[Area] && [ID_FÁBRICA] = TB_Colaboradores[ID_Fábrica]
        && TB_Treinamentos[EspCargo] = FALSE() && TB_Treinamentos[TipoCargo] = "Fábrica" ||
        TB_Treinamentos[Nivel] = "Área" && TB_Treinamentos[Especificacao] = TB_Colaboradores[Area] && [ID_FÁBRICA] = TB_Colaboradores[ID_Fábrica] 
        && [CARGO] = TB_Colaboradores[Cargo] && TB_Treinamentos[TipoCargo] = "Cargo" ||
        TB_Treinamentos[Nivel] = "Equipamento" && TB_Treinamentos[Especificacao] = TB_Colaboradores[Equipamento] && TB_Treinamentos[EspCargo] = FALSE() && TB_Treinamentos[TipoCargo] = "Organização" ||
        TB_Treinamentos[Nivel] = "Equipamento" && TB_Treinamentos[Especificacao] = TB_Colaboradores[Equipamento] && [ID_FÁBRICA] = TB_Colaboradores[ID_Fábrica] && TB_Treinamentos[TipoCargo] = "Fábrica" ||
        TB_Treinamentos[Nivel] = "Equipamento" && TB_Treinamentos[Especificacao] = TB_Colaboradores[Equipamento] && [ID_FÁBRICA] = TB_Colaboradores[ID_Fábrica] 
        && [CARGO] = TB_Colaboradores[Cargo] && TB_Treinamentos[TipoCargo] = "Cargo" ||
        TB_Treinamentos[Nivel] = "Cargo" && [CARGO] = TB_Colaboradores[Cargo] && TB_Treinamentos[TipoCargo] = "Organização" ||
        TB_Treinamentos[Nivel] = "Cargo" && [CARGO] = TB_Colaboradores[Cargo] && [ID_FÁBRICA] = TB_Colaboradores[ID_Fábrica] && TB_Treinamentos[TipoCargo] = "Fábrica" ||
        TB_Treinamentos[Nivel] = "Cargo" && [CARGO] = TB_Colaboradores[Cargo] && [AREA] = TB_Colaboradores[Area] && TB_Treinamentos[TipoCargo] = "Área" || 
        TB_Treinamentos[Nivel] = "Passo" && TB_Treinamentos[Especificacao] IN SUMMARIZE(ADDCOLUMNS(GENERATESERIES(1, VALUE(RIGHT(IF(TB_Colaboradores[Passo] = "","Passo 0",TB_Colaboradores[Passo]),1))),"Result",CONCATENATE("Passo ",[Value])),[Result]) && TB_Treinamentos[EspCargo] = FALSE()
    ), TB_Treinamentos[Grau] <> "Avançado" && TB_Treinamentos[Canal] <> "LPP"

))

 

 

Como podem perceber ela filtra e conta o número de linhas do resultado, o que eu quero é: criar uma coluna calculada que exiba esses treinamentos, de forma que, se um colaborador tiver que fazer mais de um treinamento, o seu "Nome" e "ID" sejam duplicados e o nome ou demais dados do treinamento sejam exibidos em uma coluna ao lado, conforme o exemplo abaixo:
TB_Treinamentos

IDNome
1Treinamento Teste 1
2Treinamento Teste 2
3Treinamento Teste 3


TB_Colaboradores

IDNomeNº de Treinamentos a fazer
1Colaborador 12
2Colaborador 23

 

Resultado esperado

ID_ColaboradorNome_ColaboradorNome Treinamento
1Colaborador 1Treinamento Teste 1
1Colaborador 1Treinamento Teste 2
2Colaborador 2Treinamento Teste 1
2Colaborador 2Treinamento Teste 2
2Colaborador 2Treinamento Teste 3
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Renomeei o nome de algumas colunas na TB_Colaboradores, já que na TB_Treinamentos haviam colunas com o mesmo nome, e adicionei a fórmula abaixo a uma coluna personalizada diretamente no Power Query:

let

emp = [Empresa],
idfab = [ID_Fábricass],
fab = [Fábricass],
idare = [ID_Areass],
are = [Areass],
carg = [Cargoss],
ultmu = [Última Modificação],
passo = if [Passo] <> "" then Number.FromText(Text.Range([Passo], 6, 1)) else 0,
eqp = [Equipamentoss],


Fonte = Table.Buffer(TB_Treinamentos),

freq = Table.SelectRows(Fonte, each 
[Frequencia] = "NA" or DateTime.Date([Início]) <= DateTime.Date(DateTime.LocalNow()) and DateTime.Date([Fim]) >= DateTime.Date(DateTime.LocalNow())
),

mod = Table.SelectRows(freq, each 
if ultmu <> null and Duration.Days(Date.From(ultmu)-Date.From(DateTime.LocalNow())) >= -30 then
[Início] <= ultmu else
true
),

AddCarg = Table.ExpandTableColumn(Table.NestedJoin(mod, {"ID_Cargo"}, TB_Cargos, {"ID"}, "ID_Cargoss", JoinKind.LeftOuter),"ID_Cargoss",{"ID_Area", "Nome"}, {"ID_Areass", "Nome_Cargo"}),
AddIDArea2 = Table.AddColumn(AddCarg, "ID_AREA2",
  each
    if [ID_Cargo] <> null then
      [ID_Areass]
    else
      if [ID_Area] <> null then
        [ID_Area]
      else
        null
),

AddIDFab =  Table.ExpandTableColumn(Table.NestedJoin(AddIDArea2, {"ID_AREA2"}, TB_Areas, {"ID"}, "Areax", JoinKind.LeftOuter),"Areax",{"ID_Fabrica","Nome"},{"ID_Fabrica","Nome_Area"}),

FiltroGrauLPP = Table.SelectRows(AddIDFab, each [Grau] <> "Avançado" and [Canal] <> "LPP"),

FiltroFinal = Table.SelectRows(FiltroGrauLPP, each 

[Nivel] = "Organização" and [EspCargo] = "false" or

[Nivel] = "Empresa" and [Especificacao] = emp or

[Nivel] = "Fábrica" and [Especificacao] = fab and [EspCargo] = "false" or 

[Nivel] = "Área" and [Especificacao] = are and [EspCargo] = "false" and [TipoCargo] = "Organização" or

[Nivel] = "Área" and [Especificacao] = are and [ID_Fabrica] = idfab and [EspCargo] = "false" and [TipoCargo] = "Fábrica" or

[Nivel] = "Área" and [Especificacao] = are and [ID_Fabrica] = idfab and [Nome_Cargo] = carg and [TipoCargo] = "Cargo" or 

[Nivel] = "Equipamento" and [Especificacao] = eqp and [EspCargo] = "false" and [TipoCargo] = "Organização" or

[Nivel] = "Equipamento" and [Especificacao] = eqp and [ID_Fabrica] = idfab and [TipoCargo] = "Fábrica" or 

[Nivel] = "Equipamento" and [Especificacao] = eqp and [ID_Fabrica] = idfab and [Nome_Cargo] = carg and [TipoCargo] = "Cargo" or

[Nivel] = "Cargo" and [Nome_Cargo] = carg and [TipoCargo] = "Organização" or

[Nivel] = "Cargo" and [Nome_Cargo] = carg and [ID_Fabrica] = idfab and [TipoCargo] = "Fábrica" or

[Nivel] = "Cargo" and [Nome_Cargo] = carg and [Nome_Area] = are and [TipoCargo] = "Área" or

[Nivel] = "Passo" and Number.FromText(Text.Range([Especificacao], 6, 1)) <= passo

),
    
Resultado = FiltroFinal

in

  Resultado

Após isso, basta expandir a coluna, virá com todos os treinamentos baseados no filtro e o resultado final é exatamente o que eu queria, sem contar que o Power BI ficou muito mais rápido para ser utilizado, uma vez que tirei essa fórmula bem complexa dele e inseri diretamente no Power Query em um fluxo de dados.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Renomeei o nome de algumas colunas na TB_Colaboradores, já que na TB_Treinamentos haviam colunas com o mesmo nome, e adicionei a fórmula abaixo a uma coluna personalizada diretamente no Power Query:

let

emp = [Empresa],
idfab = [ID_Fábricass],
fab = [Fábricass],
idare = [ID_Areass],
are = [Areass],
carg = [Cargoss],
ultmu = [Última Modificação],
passo = if [Passo] <> "" then Number.FromText(Text.Range([Passo], 6, 1)) else 0,
eqp = [Equipamentoss],


Fonte = Table.Buffer(TB_Treinamentos),

freq = Table.SelectRows(Fonte, each 
[Frequencia] = "NA" or DateTime.Date([Início]) <= DateTime.Date(DateTime.LocalNow()) and DateTime.Date([Fim]) >= DateTime.Date(DateTime.LocalNow())
),

mod = Table.SelectRows(freq, each 
if ultmu <> null and Duration.Days(Date.From(ultmu)-Date.From(DateTime.LocalNow())) >= -30 then
[Início] <= ultmu else
true
),

AddCarg = Table.ExpandTableColumn(Table.NestedJoin(mod, {"ID_Cargo"}, TB_Cargos, {"ID"}, "ID_Cargoss", JoinKind.LeftOuter),"ID_Cargoss",{"ID_Area", "Nome"}, {"ID_Areass", "Nome_Cargo"}),
AddIDArea2 = Table.AddColumn(AddCarg, "ID_AREA2",
  each
    if [ID_Cargo] <> null then
      [ID_Areass]
    else
      if [ID_Area] <> null then
        [ID_Area]
      else
        null
),

AddIDFab =  Table.ExpandTableColumn(Table.NestedJoin(AddIDArea2, {"ID_AREA2"}, TB_Areas, {"ID"}, "Areax", JoinKind.LeftOuter),"Areax",{"ID_Fabrica","Nome"},{"ID_Fabrica","Nome_Area"}),

FiltroGrauLPP = Table.SelectRows(AddIDFab, each [Grau] <> "Avançado" and [Canal] <> "LPP"),

FiltroFinal = Table.SelectRows(FiltroGrauLPP, each 

[Nivel] = "Organização" and [EspCargo] = "false" or

[Nivel] = "Empresa" and [Especificacao] = emp or

[Nivel] = "Fábrica" and [Especificacao] = fab and [EspCargo] = "false" or 

[Nivel] = "Área" and [Especificacao] = are and [EspCargo] = "false" and [TipoCargo] = "Organização" or

[Nivel] = "Área" and [Especificacao] = are and [ID_Fabrica] = idfab and [EspCargo] = "false" and [TipoCargo] = "Fábrica" or

[Nivel] = "Área" and [Especificacao] = are and [ID_Fabrica] = idfab and [Nome_Cargo] = carg and [TipoCargo] = "Cargo" or 

[Nivel] = "Equipamento" and [Especificacao] = eqp and [EspCargo] = "false" and [TipoCargo] = "Organização" or

[Nivel] = "Equipamento" and [Especificacao] = eqp and [ID_Fabrica] = idfab and [TipoCargo] = "Fábrica" or 

[Nivel] = "Equipamento" and [Especificacao] = eqp and [ID_Fabrica] = idfab and [Nome_Cargo] = carg and [TipoCargo] = "Cargo" or

[Nivel] = "Cargo" and [Nome_Cargo] = carg and [TipoCargo] = "Organização" or

[Nivel] = "Cargo" and [Nome_Cargo] = carg and [ID_Fabrica] = idfab and [TipoCargo] = "Fábrica" or

[Nivel] = "Cargo" and [Nome_Cargo] = carg and [Nome_Area] = are and [TipoCargo] = "Área" or

[Nivel] = "Passo" and Number.FromText(Text.Range([Especificacao], 6, 1)) <= passo

),
    
Resultado = FiltroFinal

in

  Resultado

Após isso, basta expandir a coluna, virá com todos os treinamentos baseados no filtro e o resultado final é exatamente o que eu queria, sem contar que o Power BI ficou muito mais rápido para ser utilizado, uma vez que tirei essa fórmula bem complexa dele e inseri diretamente no Power Query em um fluxo de dados.

lbendlin
Super User
Super User

"Number of Trainings to be done" is not sufficient information. You need to indicate WHICH trainings need to be done?  Why should Individual 1 not do trainings 2 and 3 ?

Anonymous
Not applicable

The number of trainings to be done is just an example, the training that an employee must do comes from the giant formula that I indicated, but the problem should not focus on that, since I already know that employee 1 has to do 2 trainings and what they are, I just want to display these trainings, one per line and also indicating that this training is related to a certain employee. At the moment I'm trying to do this directly in Power Query, where I try to do the same filter in a custom column and in the end I just "expand" the table that is returned in each row. I just couldn't do the same filters over there yet

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.