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

Subtract two rows with different months

Hello,

 

I need to create a measure to subtract two rows from the same column based on different dates. The first value needs to be the selected on the slicer and the second one is always December.

I've tried this way but it's not working. The measure returns the first value based on the slicer and the second returns the value of December, but when together the subtraction doesn't work.

 

Medida =

VAR mes = SELECTEDVALUE(tabela_data[Mês],0)

Return

CALCULATE(sum(Cockpit[Valor]), Cockpit[Indicador]="FCF ACT YTD",tabela_data[Mês]=mes) CALCULATE(sum(Cockpit[Valor]),Cockpit[Indicador]="FCF OAG YTD",tabela_data[Mês]=12)

 

I've also tried replacing the variable "mes" for "4" at the first calculate just to see if it works and it does. So I think the issue is related to the use of a variable with a subtraction

 

Help, please.

Best regard.

1 ACCEPTED SOLUTION
camargos88
Community Champion
Community Champion

Oi @Anonymous ,

 

Tenta a formula de dezembro assim:

 

CALCULATE(sum(Cockpit[Valor]), FILTER(ALL(tabela_data), Cockpit[Indicador]="FCF OAG YTD",tabela_data[Mês]=12))

 

Você precisa ignorar o filtro de data aplicado, caso contrário você não tem nenhum retorno.

 

 



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

Proud to be a Super User!



View solution in original post

7 REPLIES 7
AntrikshSharma
Community Champion
Community Champion

is the unwanted result because you are missing the subtraction sign between 2 CALCULATEs
Anonymous
Not applicable

Not that, I forgot it here, but I have it on the measure.

camargos88
Community Champion
Community Champion

Oi @Anonymous ,

 

Tenta a formula de dezembro assim:

 

CALCULATE(sum(Cockpit[Valor]), FILTER(ALL(tabela_data), Cockpit[Indicador]="FCF OAG YTD",tabela_data[Mês]=12))

 

Você precisa ignorar o filtro de data aplicado, caso contrário você não tem nenhum retorno.

 

 



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

Proud to be a Super User!



Anonymous
Not applicable

With some adjustments this solution works fine.

I just needed to implement a Filter(ALL()) to all the criteria that I want. 

 

Final result:

 

FCF OAG GAP =
Var Ano = SELECTEDVALUE(tabela_data[Ano],0)
Return
Var Mes = SELECTEDVALUE(tabela_data[Mês],0)
Return
Calculate(sum(Cockpit[Valor]),FILTER(all(Cockpit),Cockpit[Indicador]="FCF ACT YTD"),filter(all(Cockpit),Cockpit[Região]="Group"),filter(all(tabela_data),tabela_data[Mês]=Mes),FILTER(all(tabela_data),tabela_data[Ano]=Ano))-CALCULATE(sum(Cockpit[Valor]),FILTER(all(Cockpit),Cockpit[Indicador]="FCF OAG YTD"),FILTER(ALL(tabela_data),tabela_data[Mês]=12),FILTER(all(tabela_data),tabela_data[Ano]=Ano),filter(all(Cockpit),Cockpit[Região]="Group"))
 
Thanks a lot! 

@Anonymous ,

 

Não sei como você está fazendo o visual, porém talvez não seja necessário aplicar o filtro no valor atual da linha, apenas no anterior, o proprio SUM(VALOR) já vai fazer isso por você. Isso evita sobrecarga, e só vai sentir se seu modelo tem uma grande quantidade de dados.



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

Proud to be a Super User!



Anonymous
Not applicable

ola,

 

Não funciona porque dá erro de sintaxe. Não posso trazer a coluna Cockpit[Indicador] para dentro do Filter porque no All invoco  a tabela_data.

Já tentei por o filtro da Cockpit[Indicador] de fora e fazer dois FILTER, mas tambem não funciona, está-me a devolver um valor que nem sei onde está a ir buscar agora.

@Anonymous ,

 

Tenta essa:

 

Medida =
CALCULATE(SUM('Table'[VALUE]), 'Table'[Indicador] = "A") -
CALCULATE(SUM('Table'[VALUE]), FILTER(ALL('Table'), 'Table'[Indicador] = "A" && RELATED('Date'[Mes]) = 12))
 
 


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

Proud to be a Super User!



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.

Top Solution Authors