Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Data1:

ID Value 
2   114    
3   108    
4   107    
5   113    
6   112    
7   106    
8   109  

Data Required In Power BI(DAX):

ID Value last_recovery_id
2   114    5
3   108    4
4   107    X
5   113    6
6   112    7
7   106    X
8   109  

Basically I want to know the last id after which the price went higher.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
536 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can try this below measure-

last_recovery_id = 
var current_row_value = min(your_table_name[Value])
var current_row_id = min(your_table_name[ID])
var previous_max_value = 
CALCULATE(
    MAX(your_table_name[Value]),
    FILTER(
        ALL(your_table_name),
        your_table_name[Value] < current_row_value
        && your_table_name[ID] > current_row_id
    )
)

var prevous_id =  
CALCULATE(
    MAX(your_table_name[id]),
    FILTER(
        ALL(your_table_name),
        your_table_name[Value] = previous_max_value
        && your_table_name[ID] > current_row_id
    )
)

RETURN IF(prevous_id = BLANK(),"X", prevous_id)

The output is-

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...