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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
LLT1021
Helper I
Helper I

Finding previous value with measure

Hi all!

I have a question regarding previous values. 
I have a table with data about employees of a company like;

Name     Gender   Exit date          Date                Number of people leaving   Distance
X             F             01-05-2023     01-05-2023    1                                             -
X             F             01-05-2023     01-04-2023     0                                            5
Y             M                                   01-05-2023    0                                             10
Y             M                                   01-05-2023     0                                             10
I am interested in distance for the people leaving, but as you can see, when leaving (number people leaving = 1) there is no distance value, so I would like to obtain the value of the month before leaving, in this case for person X the value of distance at 01-04-2023. There is a filter in the final table displaying the info of leavers with 'Number people leaving'>0 and I am struggling with creating a measure that generates distance at the month before leaving and ignoring the number of people leaving filter.
Thanks for you help!

1 ACCEPTED SOLUTION

Hi, @LLT1021 

 

You can try the following methods.

Previous date = 
Var _leavedate=CALCULATE(MAX('Fact Employee'[Date]),FILTER(ALL('Fact Employee'),[People leaving]=1&&[Name]=SELECTEDVALUE('Fact Employee'[Name])))
Var _previousdate=CALCULATE(MAX('Fact Employee'[Date]),FILTER(ALL('Fact Employee'),[Name]=SELECTEDVALUE('Fact Employee'[Name])&&[Date]<_leavedate))
Return
IF(SELECTEDVALUE('Fact Employee'[People leaving])=1,_previousdate,BLANK())
Result = CALCULATE(MAX('Fact Financial'[Distance]),FILTER(ALL('Fact Financial'),[Name]=SELECTEDVALUE('Fact Employee'[Name])&&[Date]=[Previous date]))

vzhangti_0-1681723776586.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

6 REPLIES 6
LLT1021
Helper I
Helper I

Thanks! Works great 🙂 

v-zhangti
Community Support
Community Support

Hi, @LLT1021 

 

You can try the following methods.

Distance Measure = 
Var _Previousdate=CALCULATE ( MIN ( 'Table'[Date] ), ALLEXCEPT ( 'Table', 'Table'[Name] ) )
Return
IF ( SELECTEDVALUE ( 'Table'[Exit date] ) <> BLANK (),
    CALCULATE ( SUM ( 'Table'[Distance] ),
        FILTER ( ALL ( 'Table' ),
            [Name] = SELECTEDVALUE ( 'Table'[Name] )
                && [Date]=_Previousdate ) ),
    BLANK ()
)

vzhangti_0-1681712568431.png

Measure = IF(SELECTEDVALUE('Table'[Number of people leaving])>0,1,0)

vzhangti_2-1681712679695.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks a lot! This is already helping a lot. The only thing is that now the minimum of 'date' is taken in variable 'Previousdate' which does not always work as it should be the date before the exit date (there could be a lot more rows for person X with possibly other distance values, but the only relevant one is the one with date = exit date - 1 month)

Hi, @LLT1021 

 

Can you provide more sample data for testing? Sensitive information can be removed in advance. What kind of expected results do you expect? You can also show it with pictures or Excel.

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

LLT1021_0-1681716865068.png

Sure! I hope this is more clear.

Hi, @LLT1021 

 

You can try the following methods.

Previous date = 
Var _leavedate=CALCULATE(MAX('Fact Employee'[Date]),FILTER(ALL('Fact Employee'),[People leaving]=1&&[Name]=SELECTEDVALUE('Fact Employee'[Name])))
Var _previousdate=CALCULATE(MAX('Fact Employee'[Date]),FILTER(ALL('Fact Employee'),[Name]=SELECTEDVALUE('Fact Employee'[Name])&&[Date]<_leavedate))
Return
IF(SELECTEDVALUE('Fact Employee'[People leaving])=1,_previousdate,BLANK())
Result = CALCULATE(MAX('Fact Financial'[Distance]),FILTER(ALL('Fact Financial'),[Name]=SELECTEDVALUE('Fact Employee'[Name])&&[Date]=[Previous date]))

vzhangti_0-1681723776586.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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