cancel
Showing results for
Did you mean:

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

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[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]

1 ACCEPTED SOLUTION
Helper II

Hi @v-jayw-msft 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])
)
)

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

RETURN
KM_Anterior
4 REPLIES 4
Community Support

Hi @renanc ,

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

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
Helper II

Hi @v-jayw-msft 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])
)
)

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

RETURN
KM_Anterior
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].

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[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]``````

Announcements

#### New forum boards available in Real-Time Intelligence.

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

#### Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

#### Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors