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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
qgturismo
Helper I
Helper I

CALCULATE comparing columns with different numer of rows

Hello everyone, Could anybody help me, please?

 

I have two tables:

TABLE1: venda_cotacao

TABLE2: BI_EXP

 

On TABLE1(venda_cotacao) I'd like to create a new column (called RENTABILIDADE QG) which will compare the column venda_cotacao[id] with the column BI_EXP[Lancamento] and when the value on both are the same, then the value on the column BI_EXP[RENTS] must go to the new column (RENTABILIDADE QG). If the BI_EXP[RENTS] has more than 1 row than it should SUM all the rows.

I made this formula below and it works just fine... except when the column BI_EXP[Lancamento] has more than 1 row with the same value... on those cases, it returns blank.

 

OBS.: the column venda_cotacao[id] always has only 1 row per value but the BI_EXP[Lancamento] can have 1 or more rows per value.

 

RENTABILIDADE QG =
var JoinCol = venda_cotacao[id]
var NewCol = CALCULATE(SUM(BI_EXP[RENTS]);BI_EXP[Lancamento]=JoinCol)
return NewCol
 
Thanks a lot! 
 
Those are the 2 tables:

TABLE1: venda_cotacao                                                      TABLE2: BI_EXP

 Imagem 2.pngWhatsApp Image 2020-05-20 at 17.33.09.jpeg
 
 
 
1 ACCEPTED SOLUTION

@qgturismo ,

 

The venda_cotacao table is filtered by other columns by relationship.

The solution is to create a column ignoring the venda_terrestre_item table.

Like:

Rentabilidade_QG = CALCULATE(SUM('Table (2)'[Rents]), FILTER('Table (2)', 'Table (2)'[Lancamento] = EARLIER('Table'[id]));

ALL(venda_terrestre_item))

 

Also, take a closer look to the data modeling. So you avoid problems with columns/measure.



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

9 REPLIES 9
camargos88
Community Champion
Community Champion

Oi @qgturismo .

 

Tenta essa fórmula:

Rentabilidade_QG = CALCULATE(SUM('Table (2)'[Rents]), FILTER('Table (2)', 'Table (2)'[Lancamento] = EARLIER('Table'[id])))
 
Você pode relacionar as duas tabelas tbm e usar como medida.


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Rentabilidade_QG = CALCULATE(SUM(BI_EXP[RENTS]); FILTER(BI_EXP;BI_EXP[Lancamento]=EARLIER(venda_cotacao[id])))

 

Olá @camargos88 , muito obrigado pela pronta resposta.

Tentei a sua solução porém acaba dando o mesmo resultado da minha fórmula: Quando a coluna BI_EXP[Lancamento] tem apenas 1 linha, funciona corretamente, porém, quando tem várias linhas com o mesmo valor, volta em branco (não dá erro, mas retorna em branco)

Alguma outra ideia?

 

Obrigado

 

Hello @camargos88 thanks a lot for tour fast reply
I tried your solution but it responds the same as my original formula. When the column BI_EXP[Lancamento] has only 1 row, it works just fine, but when this column has 2 or more rows with the same value, it replies blank (no error, just blank).
 
Any other ideas?
 
Regards

@qgturismo ,

 

Estranho,

 

Me dá um exemplo ai em que tem mais de 1 valor e retorna branco.

Se for esse mesmo da foto, qual é o tipo de dados da coluna ?



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



@camargos88 copiei a tela aqui deixando apenas 2 exemplos pra facilitar.

 

Note que o lançamento 75436 tem 3 linhas (2 linhas com valor 0,00 e 1 linha com valor 88,33) e nesse caso, a resposta pra formula vem branco

O lançamento 75437 tem 2 linhas (1 com valor 0,00 e 1 linha com o valor 13,04) nesse caso, a resposta pra formula vem 13,04 que é a resposta correta

 

 

TABLE1: venda_cotacao / TABLE2: BI_EXP

1.png2.png

@qgturismo ,

 

Qual é o tipo de dados das colunas ?



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



@camargos88 ,

 

venda_cotacao[id] BI_EXP[Lancamento ambas são NUMERO INTEIROS

BI_EXP[RENTS] e a novavenda_cotacao[Rentabilidade_QG] ambas são MOEDA R$

 

Foi essa a pergunta? Desculpe se não entendi...

@qgturismo ,

 

The venda_cotacao table is filtered by other columns by relationship.

The solution is to create a column ignoring the venda_terrestre_item table.

Like:

Rentabilidade_QG = CALCULATE(SUM('Table (2)'[Rents]), FILTER('Table (2)', 'Table (2)'[Lancamento] = EARLIER('Table'[id]));

ALL(venda_terrestre_item))

 

Also, take a closer look to the data modeling. So you avoid problems with columns/measure.



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Thank you very much for the hard effort and help.

 

Regards

@qgturismo ,

 

Muito estranho isso, tem como vc gerar um pbix apenas com esses dois casos e compartilhar ?

Tentei reproduzir aqui mas funciona.



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.