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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
renanc
Helper II
Helper II

Calculate the values between two lines

Hi everybody, I have a calculated value on Dax, but it calculates the value between the current fuel fill and the next one. I want to calculate the value between the current fuel fill and the previous one. Can abybody help me with this, please?

The Dax formula used is here, and attachet below.

Thank you

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]


renanc_0-1653922787158.png

renanc_1-1653922804680.png

 

1 ACCEPTED SOLUTION

Hi @Anonymous I found the solution for this case, it was:

KM Anterior =
VAR Ultimo_Checklist =
CALCULATE(
MAX(fChecklists2[IdChecklist]),
FILTER(
ALL(fChecklists2),
(fChecklists2[DescPlaca])=EARLIER([DescPlaca])
&& fChecklists2[IdChecklist] < EARLIER([IdChecklist])
&& fChecklists2[IdQuestionario] = EARLIER([IdQuestionario])
&& fChecklists2[DtCadastro] <= EARLIER([DtCadastro])
)
)

VAR KM_Anterior =
CALCULATE(
MAX(fChecklists2[Digite a KM]),
FILTER(
ALL(fChecklists2),
fChecklists2[IdChecklist] = Ultimo_Checklist
)
)

RETURN
KM_Anterior

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @renanc ,

 

Please share some sample data so that we could test the formula on it.

 

Best Regards,

Jay

Hi @Anonymous I found the solution for this case, it was:

KM Anterior =
VAR Ultimo_Checklist =
CALCULATE(
MAX(fChecklists2[IdChecklist]),
FILTER(
ALL(fChecklists2),
(fChecklists2[DescPlaca])=EARLIER([DescPlaca])
&& fChecklists2[IdChecklist] < EARLIER([IdChecklist])
&& fChecklists2[IdQuestionario] = EARLIER([IdQuestionario])
&& fChecklists2[DtCadastro] <= EARLIER([DtCadastro])
)
)

VAR KM_Anterior =
CALCULATE(
MAX(fChecklists2[Digite a KM]),
FILTER(
ALL(fChecklists2),
fChecklists2[IdChecklist] = Ultimo_Checklist
)
)

RETURN
KM_Anterior
renanc
Helper II
Helper II

Hi @johnt75, actually it did not work. In the new column (Diferenca KM 2), the values are negative values of those we have in Digite a KM.  Probably the term inside 

CALCULATE (
        MIN ( [Digite a KM] ),
        FILTER (
            ALL ( fChecklists ),
            fChecklists[IdChecklist] = _max
                && fChecklists[DescPlaca] = EARLIER ( [DescPlaca] )
                && fChecklists[IdQuestionario] = EARLIER ( [IdQuestionario] )
        )

is returning 0 or a null value, and then subtracting [Digite a KM].

Thank you for your help

renanc_0-1653929384041.png

 

johnt75
Super User
Super User

You can try

Diferenca KM =
VAR _max =
    CALCULATE (
        LASTNONBLANK ( 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] = _max
                && fChecklists[DescPlaca] = EARLIER ( [DescPlaca] )
                && fChecklists[IdQuestionario] = EARLIER ( [IdQuestionario] )
        )
    ) - [Digite a KM]

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors