Forum Discussion

rafaelsmoreno's avatar
rafaelsmoreno
Frequent Visitor
7 years ago
Solved

Countif as a function in M - Power Query

Hi   I am trying to create a function that would emulate the countif from excel into power query. I tried the code at this post below, but it is just not working for me.   https://community.power...
  • ImkeF's avatar
    ImkeF
    7 years ago

    rafaelsmoreno wrote:

    ... 

    Base_documentos is the query in which I am running the code. Is that a problem? Should I place instead of Base_documentos the previous stage of the query?

     ...

     

     

     


    Yes, that's causing the circular dependency error. 

    As you said: Take the previous step name instead.

     

    Actually: You should take the buffered previous step name: 

     

    let

    ...

     

    #"Personalização Adicionada3" = Table.AddColumn(#"Índice Adicionado","contCHAVE", each fcountif(Table.Buffer(PreviousStepName), "CHAVE", [Índice])),
    #"Personalização Adicionada4" = Table.AddColumn(#"Personalização Adicionada3","contCHAVEOR", each fcountif(Table.Buffer(PreviousStepName), "CHAVEOR", [Índice]))


    in
    #"Personalização Adicionada4"

     

    Thanks for the follow ;)