How to get the first non-empty field value of a referenced entity in views? The website has two content types:
Magazine and issue.
I'm using the Entity Reference module to create a magazine archive website.

I have a views that list all magazines. Each magazine is with an image of issue that related to this magazine. There is a relationship (entity reference: referencing entity) and the aggregation setting is active (use aggregation).
Everything is OK but there is a problem I couldn't solve.
The image for each magazine is the image of the first issue of this magazine. But not every &quot;first issue&quot; has an image and it shows the default image.
What I want to do is to show the first issue's image that's image field is non-empty or show any related issue's image on this views. How can I do that?
Note: Some magazine's any issues doesn't have any image and if I filter out these issues, then the related magazine will not be shown. I think what I want to do is if any of the issue has an image show it or show the default image.
From Everything is OK but there is a problem I couldn't solve I supposed you successfully create a view of issues and their related magazine and I focus on the problem.

There are two cases, 


at least one of the issues has an image
non of them has an image


In order to create a view for case 1, you need to modify your existing view to have sort criteria on image_field:fid (Issue image field, using relationships you can have this)



and sort it descending

and set the Pager to:  

Use pager:
Display a specified number of items| 1 item

in this way, if there is any issue with an image, the first one that has image is displayed.

Lets handle the case where there is no issue with image. The image field is displayed in here, it can be in a &lt;div views-field views-field-field-image&gt;&lt;/div&gt;, but it is empty. We have to insert a default image in it. Simply add css like this to your theme

.views-field-field-image{
       width: ...px;// you standard display of width
       height: ...px;// you standard display of height
       display: inline-block;
       background-image: url('');


Now if there is an image, the &lt;div views-field views-field-field-image&gt;&lt;/div&gt; layer will go behind the image and it will not be shown and if there is no image, we have set the &lt;div&gt; dimension and also an image for it to be displayed.