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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
renanc
Helper II
Helper II

Calculate the difference of values in a column within a same value in another column

Hi everybody,

I am trying to calculate the difference of the KM between the checklists, for the same car plate (DescPlaca), and I am trying to do the Context in the same way I would do for DATEDIFF, but for some reason it does not work. Can anybody help me with this, please?
I wanna calculate the "Digite a KM" value less the Previous checklist "Digite a KM" value, for this, I have to use IdChecklist, so the IdChecklist for the first term has to be bigger than IdChecklist for the second term, and DescPlaca has to be equal.
I am trying to use the following dax. can anybody spot what is wrong, please?

Diferenca KM =
CALCULATE(
FIRSTNONBLANK(fChecklists[IdChecklist],0),
FILTER(
ALL(fChecklists),
fChecklists[IdChecklist] > EARLIER([IdChecklist])
&& fChecklists[DescPlaca]=EARLIER([DescPlaca])
&& fChecklists[DtCadastro] >= EARLIER([DtCadastro])
&& fChecklists[IdQuestionario] = EARLIER([IdQuestionario])
)
)

 01.jpg

3 REPLIES 3
renanc
Helper II
Helper II

Hi @amitchandak, I was trying to create as a measure, now I tried to create anew column.
In the var _min calculation, the Dax recognizes the columns DescPlaca and IdQuestionario, but in the calculation in the return, these columns are not recognized. The following mesage appears: 

Parameter is not the correct type.
Cannot find name '[DescPlaca]'

 



renanc_0-1651082642445.png

 

@renanc 
You missed a comma "," after min([Digite a KM])

amitchandak
Super User
Super User

@renanc , A new column like

 

Diferenca KM =
var _min =
CALCULATE(
FIRSTNONBLANK(fChecklists[IdChecklist],0),
FILTER(
ALL(fChecklists),
fChecklists[IdChecklist] > EARLIER([IdChecklist])
&& fChecklists[DescPlaca]=EARLIER([DescPlaca])
&& fChecklists[DtCadastro] >= EARLIER([DtCadastro])
&& fChecklists[IdQuestionario] = EARLIER([IdQuestionario])
)
)
return
CALCULATE(
min([Digite a KM])
FILTER(
ALL(fChecklists),
fChecklists[IdChecklist] = _min
&& fChecklists[DescPlaca]=EARLIER([DescPlaca])
&& fChecklists[IdQuestionario] = EARLIER([IdQuestionario])
)
) - [Digite a KM]

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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