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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
renanc
Helper II
Helper II

Calculate the values between two lines within the same value in another column

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_3-1654086189757.png

 


 

renanc_2-1654085887860.png

 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @renanc,

You can try to use the following formula if helps: (I try to lookup the previous date based on the current place and date)

Diferenca KM =
VAR _prevDate =
    CALCULATE (
        MAX ( fChecklists[Date] ),
        FILTER (
            fChecklists,
            fChecklists[Date] < EARLIER ( fChecklists[Date] )
                && fChecklists[DescPlaca] = EARLIER ( [DescPlaca] )
                && [Digite a KM] <> BLANK ()
        )
    )
RETURN
    CALCULATE (
        SUM ( [Digite a KM] ),
        FILTER (
            fChecklists,
            fChecklists[Date] = _prevDate
                && fChecklists[DescPlaca] = EARLIER ( [DescPlaca] )
        )
    ) - fChecklists[Digite a KM]

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

HI @renanc,

You can try to use the following formula if helps: (I try to lookup the previous date based on the current place and date)

Diferenca KM =
VAR _prevDate =
    CALCULATE (
        MAX ( fChecklists[Date] ),
        FILTER (
            fChecklists,
            fChecklists[Date] < EARLIER ( fChecklists[Date] )
                && fChecklists[DescPlaca] = EARLIER ( [DescPlaca] )
                && [Digite a KM] <> BLANK ()
        )
    )
RETURN
    CALCULATE (
        SUM ( [Digite a KM] ),
        FILTER (
            fChecklists,
            fChecklists[Date] = _prevDate
                && fChecklists[DescPlaca] = EARLIER ( [DescPlaca] )
        )
    ) - fChecklists[Digite a KM]

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Power BI Monthly Update - May 2024

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