'it worked but took too long. How can it work faster? optimization dax code

it worked but took too long. How can it work faster? i have two tables connected by relationship via lead_id. Need to get the lead_id that satisfies the status and the latest status change time. I was able to get the right results but the code execution time was too slow. Is there any way to improve my speed? Thanks

L4_5 = 
VAR L1_3 = 
SELECTCOLUMNS(
    CALCULATETABLE(
        'public leadHistory_status',
        'public leadHistory_status'[statusBeforeChange] IN {"L1A","L1B","L1C","L2A","L2B","L2C","L2D","L2E","L2F","L2G","L2V","L3A","L3B","L3C","L3D"}),
    "lead_id",
    'public leadHistory_status'[lead_id]
)
VAR finalChangedTime = 
    SUMMARIZE(
            'public leadHistory_status',
            'public leadHistory_status'[lead_id],
            "Max Time",
            max('public leadHistory'[changedTime])
        )
VAR L4_5 = 
    CALCULATE (
        COUNTROWS ( 'public leadHistory_status' ),
        'public leadHistory_status'[lead_id] IN L1_3,
        ('public leadHistory'[lead_id],'public leadHistory'[changedTime]) IN finalChangedTime,
        'public leadHistory_status'[statusAfterChange] IN {"L4A","L4B","L4X","L5A","L5B","L5C","L5D"}
        )
return L4_5


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source