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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
bbdeveloper
Frequent Visitor

Lookup a value from the next row in a group/partition

I am trying to create a calculated column "NextValidWW" which gets the next greater workweek partitioned by the ProjectID and TaskID. See below:

1.jpg

 

In SQL, I was able to achieve this by:

 

LEAD(StatusWW) 	OVER (
    PARTITION BY TaskUID, 
    ProjectID 	
    ORDER BY StatusWW
    )

 

I found a post on reddit where it gives a very similar solution, but I am not getting my desired outcome:

 

TRY 1:
This works when the "next" greater work week is only greater than the StatusWW by 1 - but does not account for cases when the "next" greater work week could be greater than 1.

 

=CALCULATE(        
    VALUES(DCN_NextWW[StatusWW]),
        ALLEXCEPT(DCN_NextWW, DCN_NextWW[ProjectID], DCN_NextWW[TaskUID]), 
        DCN_NextWW[StatusWW] = EARLIER(DCN_NextWW[StatusWW]) + 1 )

 

2.jpg

 

TRY 2:
This just gives me ERROR - which I understand it's returning all values that are greater than StatusWW - not just the "next" greater value

 

=CALCULATE(        
    VALUES(DCN_NextWW[StatusWW]),
        ALLEXCEPT(DCN_NextWW, DCN_NextWW[ProjectID], DCN_NextWW[TaskUID]), 
        DCN_NextWW[StatusWW] > EARLIER(DCN_NextWW[StatusWW]))

 

It seems like TRY 2 could use more conditions where [StatusWW] < the next [StatusWW] but I am not sure how to do that in DAX.. there is no NEXT() function that I am aware of

1 ACCEPTED SOLUTION
bbdeveloper
Frequent Visitor

Found a solution on another community post 

CALCULATE(
	MIN(DCN_NextWW[StatusWW]),
	FILTER(
	       DCN_NextWW,
	       DCN_NextWW[StatusWW] > EARLIER(DCN_NextWW[StatusWW]) && (DCN_NextWW[ProjectID] = EARLIER(DCN_NextWW[ProjectID]) && DCN_NextWW[TaskUID] = EARLIER(DCN_NextWW[TaskUID]))))

View solution in original post

1 REPLY 1
bbdeveloper
Frequent Visitor

Found a solution on another community post 

CALCULATE(
	MIN(DCN_NextWW[StatusWW]),
	FILTER(
	       DCN_NextWW,
	       DCN_NextWW[StatusWW] > EARLIER(DCN_NextWW[StatusWW]) && (DCN_NextWW[ProjectID] = EARLIER(DCN_NextWW[ProjectID]) && DCN_NextWW[TaskUID] = EARLIER(DCN_NextWW[TaskUID]))))

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.