Page MenuHomePhabricator

Allow grouping by date properties
Closed, ResolvedPublic

Description

For some content, the most pertinent grouping would be by a date property. This would need the ability to specify a granularity (for example, group by year/decade/century)

This could be useful for works with a regular publication, like TV soaps (that generally don't have seasons) or comic-strips. Century-grouping could be useful for eg battles, elected individuals, writers etc.

Event Timeline

A hack would be to check if grouping starts with a Pid. If not then escape the wdt: prefix allowing for more complex statements. That would in theory open up for other convenience switches based on input (e.g. year:P577) in the future.

A hack would be to check if grouping starts with a Pid. If not then escape the wdt: prefix allowing for more complex statements. That would in theory open up for other convenience switches based on input (e.g. year:P577) in the future.

That sounds like T224229: Grouping by property is not powerful enough for some use-cases, which is more or less tractable (mostly I’d need to make up my mind :)

I think grouping by date would be more complicated, as every other query would need to be time aware:

  • currently queries are smth like
SELECT ?grouping (COUNT(DISTINCT ?entity) as ?count) WHERE {
  ?entity wdt:P31 wd:Q41960.
  ?entity wdt:P551 ?grouping .
  FILTER EXISTS { ?entity p:P19 [] } .
}
GROUP BY ?grouping
  • I assume they would need to be smth like, for grouping by year:
SELECT ?grouping (COUNT(DISTINCT ?entity) as ?count) WHERE {
  ?entity wdt:P31 wd:Q41960.
  ?entity wdt:P569 ?date .
  BIND(YEAR(?date) AS ?grouping). 
  FILTER EXISTS { ?entity p:P19 [] } .
}
GROUP BY ?grouping

A plain YEAR turns out to be easy enough ; however per @Ash_Crow ’s original post, users might want to group by century or month, which would be another story...

Support was added back with 0a8e7fb, and since da99820 there is no need to configure it explicitly, as is automatically inferred based on the property datatype.

What’s missing is the granularity to get decade/century. We could make this a setting but I’m tempted towards an auto-rollup feature − if the number of year groupings retrieved > N, then automatically roll up to decade.

What’s stumps me still is the queries/looking glass feature. It relies currently on queries like

SELECT DISTINCT ?entity ?entityLabel ?value ?valueLabel WHERE {
  ?entity wdt:P31 wd:Q7889 .
  ?entity wdt:P577 ?date.
  BIND(YEAR(?date) as ?year).
  FILTER(?year = 2006).
  ?entity p:P400 ?prop . OPTIONAL { ?prop ps:P400 ?value }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

How to make it work for 2000s?

💡 (thanks to “Fictional characters whose birth/death date is in the current decade” from the Query Service example page

BIND(YEAR(?date) as ?year).
BIND(xsd:integer(?year/10) as ?decade).
FILTER(?decade = 200).

Mentioned in SAL (#wikimedia-cloud) [2026-03-14T15:45:09Z] <wmbot~jeanfred@tools-bastion-15> Deploy 8a735a0 (Add automatic date resolution rebinning for year groupings) for T236590

Mentioned in SAL (#wikimedia-cloud) [2026-03-14T15:45:36Z] <wmbot~jeanfred@tools-bastion-15> Deploy 5134f77 (Use ka/Ma unit suffixes for geological-scale year grouping headings) for T236590

JeanFred claimed this task.

Now that R2566:8a735a0c291b: Add automatic date resolution rebinning for year groupings has landed, I believe we’re done.

’m happy with how this evolved:

  • grouping by date is supported
  • it triggers on its own, without the need for explicit configuration
  • the rebinning makes it usable for various types of datasets (again, no configuration required)

Closing as resolved − only took over 6 years :)