5

I have a table with the number of buildings constructed per time period in each district, and I would like to determine the time period in which most buildings were built.

For example, for the following table, I'd like to get create a field containing "1971_2000".

District name 1945_1970 1971_2000
District 1 2 5

Is there any way to achieve this?

2 Answers 2

5

With the Field Calculator and expressions. In this solution it is only necessary to write which fields are not to be considered in the calculation, all the other fields are taken automatically:

with_variable('sel',
        array_filter(
                map_avals(attributes()), @element not in ("District_name")
                ),
        map_akeys(attributes())[array_find(@sel, array_max(@sel))]
        )

enter image description here


References:

0
3

Use this expression in the Field Calculator and change field names (if necessary, here on lines 4-5, you can add more lines if you have more fields with the same pattern):

with_variable(
    'map',
    map(
        '1945_1970',"1945_1970",
        '1971_2000',"1971_2000"
    ),
    array_get(
        map_akeys(@map),
        array_find(
            map_avals(@map),
            array_max(map_avals(@map))
        )
    )
)

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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