I'm using Views merge rows to grouping rows by some fields, It worked good for me, but in some fields I want to show just the first filled value that means: merge uniques values+use the first value.

View after using VMR
enter image description here
Orginal view
enter image description here

Is there a way to do that using views merge rows? or I have to use an other solution?
Or how I can hide/remove rows which have cycle smaller than the max cycle value for every every container -see the image above-? I couldn't do it with views filter.

I'll explain my use case below to show the purpose of creating this view:

The objective was tracking the containers, so I have to show containers and there currents and previous places.
The container pass by a number of positions (in depot, at port of delivery, at port of loading...) until being in the vessel( position: on board), or it can be in an exceptional position like "reformed". I called the passage through those positions from the start to the end a "cycle"
If the container is on board we have to fill all information about previous positions in a form "bill of lading".
What I did as solution, I created 3 content type : container,position,bill of lading.
The position content type reference the container and contains a select list field "position container" and 10 field collection field, every field collection contains a specifics fields for a single position.
So for every node position, I fill the field container, I select "position container" , I fill the field collection fields corresponding to the position selected. For example if I created a new position for the container "blk001" in position "in depot", I fill the field collection fields "name depot" and "date in depot".
For the bill of lading content type it reference the containers also, I redirect to it every time the node position is saved and "position container" is "on board".
Now the challenge is providing a list of containers,with the current bill of lading "N° B/L", the current cycle and merging all the positions fields corresponding to this cycle.


Sure there is probably some way to do that with PHP or an advanced SQL query. I recommend looking at Views Aggregator Plus as it allows you to aggregrate over Views PHP values.

Views is a simple query builder. When you want to do something really really complex, it can be useful to try to do some business logic outside of the views admin ui.

  • My view is really complex , the fields are from many content type and field collections and there will be some other calulated fields, Views merge rows and views php were achieve most of my objectif,my question is how to show just the only filled value by using this 2 modules. I have tried VAP, It's not allow me to compress by two fields.
    – learner123
    Jul 29 '15 at 7:48

I am providing a 2nd answer, as it's drastically different from the 1st. I believe my 1st answer may still help others.

I repeat -- you're trying to do something that is essentially too complex for Views by itself, and you'll have a hard time finding a magical set of Views related modules that will be allow you to create all the business logic you want within Views SQL.

If you could try to make the raw (non-Drupal SQL) you wanted that achieved this query with the data you have as-is, you could then try to use Views Extra Handlers to contain the custom SQL needed, or hook_query_alter to change the query Views uses to achieve the result you want.

I suspect this would difficult, and I suspect you don't know what raw SQL would achieve the list you want.

So I keep saying your task is difficult as-is, with the data you have on hand and the format of the data. Make you're life easier and give yourself more data. You merge results provides multiple date of loading. From all possible entries for a Container (such as BLK001).

Here's a suggestion:

  • Use Rules
  • Add a custom field called is_first_load_date as boolean value to your content default.
  • Default it to FALSE for all entries of your content type.
  • Using Rules on node insert scan all Containers of title BLK001 and examine date_of_loading -- if the newly inserted Node is the earliest date to be loaded set is_first_load_date to TRUE, set all other NIDs of this Container to FALSE.
  • Update your query to use this new piece of data, which is simpler to compute using Views.

So that's my new solution for you. Save or compute new additional data you store per-record to make your Views query easier. If you dont like Rules, then use Computed Field, but Rules is more flexible.

I dont know if my exact field you want to aggregate or merge is correct from all the details you've provided. I don't really care what your exact SQL problem is. I'm recommending you approach the solution from a different direction outside of the Views Admin UI.

  • Thanks tenken for your responses.I agree with you that is too difficult or impossible to do this via UI admin,I'm trying your approach as last chance to produce this views, before I move to do custom SQL queries for views -I know SQL but I never use it for drupal-. In order to show you how my view is complicated I edited my question and I add a short explanation of my use case.
    – learner123
    Jul 31 '15 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.