Forum Discussion
Countif as a function in M - Power Query
- 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 ;)
Code looks perfectly fine to me.
Does error arise when you click on the step #"Personalização Adicionada4" or at a later stage?
Does the table "Base_documentos" depend on this query?
Hi Imke! You are the BI Accountant, nice to meet you. I follow you on twitter.
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?
The error I got is that the moment I close the code editor and the query refreshes to show the two new added columns, they are there, but every single field is "ERROR". When I click on them, the circular reference error message pops up.
So, basically, I need to countif in the very query I'm running and I was using this piece of code. If that's not the kind of function that will give me that, what kind of function would that be?
Thanks in advance,
- ImkeF7 years agoCommunity Champion
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 ;)
- rafaelsmoreno7 years agoFrequent Visitor
Hi Imke!
I tried this code and now there is no error message in the fields, but all of them came up with 0 (zero) :(
- ImkeF7 years agoCommunity Champion
It worked for me.
So next step would be that you post some sample data and the code you've used so far.