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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors