Show only active membership in Membership list page

After signup to a membership. When the member logins and visits the membership list page need to show only the members current membership. Is that possible?

Tried the following code but it still shows the mebership those are canceled but still has trial period. Need to show only the membership active and hide all others including the one canceled but have trial period.
add_filter( 'ms_view_shortcode_membershipsignup_data', 'ms_show_only_member_memberships', 10, 2 );
function ms_show_only_member_memberships( $data, $shortcode ) {
if ( isset( $data['memberships'] ) && is_user_logged_in() ) {

$memberships = $data['memberships'];
$member = MS_Model_Member::get_current_member();
$subscriptions = MS_Model_Relationship::get_subscriptions(
array(
'user_id' => $data['member']->id,
'status' => 'valid',
)
);
$user_memberships = array();
foreach ( $subscriptions as $subscription ) {

if ( $subscription->status === MS_Model_Relationship::STATUS_ACTIVE || $subscription->status ===MS_Model_Relationship::STATUS_TRIAL ) {
$membership_id = $subscription->membership_id;
foreach ( $memberships as $membership ) {
if ( $membership->id === $membership_id ) {
$user_memberships[] = $membership;
}
}
}
}
$data['memberships'] = $user_memberships;
}
return $data;
}