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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
ftorres
Helper I
Helper I

filter context different

Someone could help me with this query. I need to create a measure that work as "Sum Years" Column. That is accumulating the years but with one condition, the date of joining has to be the date of leaving on line above + 1. Any idea how I could work with this?

pb.png

3 REPLIES 3
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @ftorres ,

Based on my test, you could refer to below formulas:

b = LOOKUPVALUE(Table1[Date of Joining],'Table1'[Date of Joining],'Table1'[Date of Leaving]+1)
Var = var a = LOOKUPVALUE(Table1[Date of Joining],Table1[b],[Date of Joining])
return IF(a=BLANK()&&'Table1'[b]=BLANK(),BLANK(),[Date of Joining])
SUM Year = IF(ISBLANK('Table1'[Var]),[Years],CALCULATE(SUM(Table1[Years]),FILTER('Table1','Table1'[Var]<=EARLIER(Table1[Var])&&'Table1'[Var]<>BLANK())))

Result:

1.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-danhe-msft,

 

Thanks for the help, but I got a problem when I try to get the var column. My sample is simple. when I apply that in my table it returns a error that "a table of multiple values was supplied where a single value was expected." The ResID in the sample is only one employee, there are loads in the database.  

Hi @ftorres ,

Could you have tried to add an index for your data model?

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.