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
aj1107
Helper I
Helper I

Getting the next status to current column

 

Hello,

 

I need to check next status(st)=open for an id and then update the current row with a flag=A. I tried with earlier function but unable to get the expected result. Please suggest how to implement using DAX.

 

id,st,cdate,flag

1,st,jan17,A

1,open,feb17,NULL

 

Thank you

1 ACCEPTED SOLUTION

@aj1107

 

In this scenario, you can create a measure for next date first.

 

NextDate =
CALCULATE (
    MIN ( 'Table'[Date] ),
    FILTER (
        ALLEXCEPT ( 'Table', 'Table'[Id] ),
        'Table'[Date] > MAX ( 'Table'[Date] )
    )
)

Then create a calculated column to lookup the corresponding Status based on NextDate.

 

 

NextStatus =
LOOKUPVALUE (
    'Table'[Status],
    'Table'[Date], [NextDate],
    'Table'[Id], 'Table'[Id]
)

55.PNG

 

 

Regards,

View solution in original post

5 REPLIES 5
prateekraina
Memorable Member
Memorable Member

Hi @aj1107,

 

What happens to the previous row? Should the flag be changed to NULL from A in that?

 

Prateek Raina

Hi

 

I've added few more records. whenever next st is open for the ID set then update current row as A. if the next st is <>open or no more records for the id Set (last row of each id) then NULL. 

 

id,st,cdate

1,close,jan17,A

1,open,feb17,NULL

1,close,mar17,A

1,open,apr17,NULL

 

2,st,jan17,NULL

 

3,st,jan17,A

3,open,Feb17,NULL

Hi @aj1107,

 

How about below DAX:

Flag = IF(Table1[St] = "Open","NULL","A")

Gives below result:
Solution1.PNG

 

Does it work for you?

 

Prateek Raina

My bad. I missed the logic . Actually in flag column i need to bring the next status to current row.(similar to lead function in sql) Please find below.

 

id,st,cdate

1,open,jan17,Open

1,open,feb17,open

1,open,mar17,close

1,close,apr17,NULL

 

2,st,jan17,NULL

 

3,open,jan17,close

3,close,Feb17,NULL

@aj1107

 

In this scenario, you can create a measure for next date first.

 

NextDate =
CALCULATE (
    MIN ( 'Table'[Date] ),
    FILTER (
        ALLEXCEPT ( 'Table', 'Table'[Id] ),
        'Table'[Date] > MAX ( 'Table'[Date] )
    )
)

Then create a calculated column to lookup the corresponding Status based on NextDate.

 

 

NextStatus =
LOOKUPVALUE (
    'Table'[Status],
    'Table'[Date], [NextDate],
    'Table'[Id], 'Table'[Id]
)

55.PNG

 

 

Regards,

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.