Skip to main content
added 259 characters in body
Source Link
Babel
  • 74.9k
  • 15
  • 87
  • 227

If you have everything on one layer (as it seems to be the case), you should use aggregate functions and filter the aggregated city_names by conty_name to create an array with all cities in a county using array_agg() function. From this array, loop through each element (city) to get the respective attribute values for the fiels people_ok and people_not_ok.

Edit: I tested your sample project and had to make only small adjustments. Use a text layout element, not an attribute table layout element, to introduce this text, as you don't really need an attribute table element for this, you use it to create a text, containing different attribute values concatenated. HOwever, the expression also works if you intreroduce it in the attribute table layout element. 

Use the expression below:

enter image description here

with_variable(
    'county',
    county_nam,
    array_to_string(
        array_foreach(
            array_agg (
                city_name, 
                filter:="county_nam"=@county
            ),
            @element 
            || ': '  || 
            attribute(
                get_feature('counties_cities','city_name', 'Messine'@element),
                'people_ok'
            )  
            || ' % of people are OK and'and ' || 
            attribute(
                get_feature('counties_cities','city_name', 'Messine'@element),
                'people_not'
            )
            ||  ' % are not'
        ),
        delimiter:= '\n' 
    )
)

If you have everything on one layer (as it seems to be the case), you should use aggregate functions and filter the aggregated city_names by conty_name to create an array with all cities in a county using array_agg() function. From this array, loop through each element (city) to get the respective attribute values for the fiels people_ok and people_not_ok.

Edit: I tested your sample project and had to make only small adjustments. Use a text element, not an attribute table, to introduce this text. Use the expression below:

enter image description here

with_variable(
    'county',
    county_nam,
    array_to_string(
        array_foreach(
            array_agg (
                city_name, 
                filter:="county_nam"=@county
            ),
            @element 
            || ': '  || 
            attribute(
                get_feature('counties_cities','city_name', 'Messine'),
                'people_ok'
            )  
            || ' % of people are OK and'  || 
            attribute(
                get_feature('counties_cities','city_name', 'Messine'),
                'people_not'
            )
            ||  ' % are not'
        ),
        delimiter:= '\n' 
    )
)

If you have everything on one layer (as it seems to be the case), you should use aggregate functions and filter the aggregated city_names by conty_name to create an array with all cities in a county using array_agg() function. From this array, loop through each element (city) to get the respective attribute values for the fiels people_ok and people_not_ok.

Edit: I tested your sample project and had to make only small adjustments. Use a text layout element, not an attribute table layout element, to introduce this text, as you don't really need an attribute table element for this, you use it to create a text, containing different attribute values concatenated. HOwever, the expression also works if you intreroduce it in the attribute table layout element. 

Use the expression below:

enter image description here

with_variable(
    'county',
    county_nam,
    array_to_string(
        array_foreach(
            array_agg (
                city_name, 
                filter:="county_nam"=@county
            ),
            @element 
            || ': ' ||
            attribute(
                get_feature('counties_cities','city_name', @element),
                'people_ok'
            )
            || ' % of people are OK and ' ||
            attribute(
                get_feature('counties_cities','city_name', @element),
                'people_not'
            )
            || ' % are not'
        ),
        delimiter:= '\n' 
    )
)
added 358 characters in body
Source Link
Babel
  • 74.9k
  • 15
  • 87
  • 227

If you have everything on one layer (as it seems to be the case), you should use aggregate functions and filter the aggregated city_names by conty_name to create an array with all cities in a county using array_agg() function. From this array, loop through each element (city) to get the respective attribute values for the fiels people_ok and people_not_ok.

SeeEdit: I tested your sample project and had to make only small adjustments. Use a text element, not an attribute table, to introduce this text. Use the expression below.:

enter image description hereenter image description here

with_variable(
    'county',
    county_namecounty_nam,
    array_to_string(
        array_foreach(
            array_agg (
                city_name, 
                filter:="county_name"=@county="county_nam"=@county
            ),
            @element 
            || ': '  || 
            attribute(
                get_feature(@layer'counties_cities','city_name', @element'Messine'),
                'people_ok'
            )  
            || ' % of people are OK and'  || 
            attribute(
                get_feature(@layer'counties_cities','city_name', @element'Messine'),
                'people_not_ok''people_not'
            )
            ||  ' % are not'
        ),
        delimiter:= '\n' 
    )
)

If you have everything on one layer (as it seems to be the case), you should use aggregate functions and filter the aggregated city_names by conty_name to create an array with all cities in a county using array_agg() function. From this array, loop through each element (city) to get the respective attribute values for the fiels people_ok and people_not_ok.

See the expression below.

enter image description here

with_variable(
    'county',
    county_name,
    array_to_string(
        array_foreach(
            array_agg (
                city_name, 
                filter:="county_name"=@county
            ),
            @element 
            || ': '  || 
            attribute(
                get_feature(@layer,'city_name', @element),
                'people_ok'
            )  
            || ' % of people are OK and'  || 
            attribute(
                get_feature(@layer,'city_name', @element),
                'people_not_ok'
            )
            ||  ' % are not'
        ),
        delimiter:= '\n' 
    )
)

If you have everything on one layer (as it seems to be the case), you should use aggregate functions and filter the aggregated city_names by conty_name to create an array with all cities in a county using array_agg() function. From this array, loop through each element (city) to get the respective attribute values for the fiels people_ok and people_not_ok.

Edit: I tested your sample project and had to make only small adjustments. Use a text element, not an attribute table, to introduce this text. Use the expression below:

enter image description here

with_variable(
    'county',
    county_nam,
    array_to_string(
        array_foreach(
            array_agg (
                city_name, 
                filter:="county_nam"=@county
            ),
            @element 
            || ': '  || 
            attribute(
                get_feature('counties_cities','city_name', 'Messine'),
                'people_ok'
            )  
            || ' % of people are OK and'  || 
            attribute(
                get_feature('counties_cities','city_name', 'Messine'),
                'people_not'
            )
            ||  ' % are not'
        ),
        delimiter:= '\n' 
    )
)
added 468 characters in body
Source Link
Babel
  • 74.9k
  • 15
  • 87
  • 227

UseIf you have everything on one layer (as it seems to be the case), you should use aggregate functions and filter the aggregated city_names by conty_name to create an array with all cities in a county using array_agg() function. From this array, loop through each element (city) to get the respective attribute values for the fiels people_ok and people_not_ok.

See the expression: below.

enter image description here

with_variable(
    'county',
    county_name,
    array_to_string(
        array_foreach(
            array_agg (
                city_name, 
                filter:="county_name"=@county
            ),
            @element 
            || ': '  || 
            attribute(
                get_feature(@layer,'city_name', @element),
                'people_ok'
            )  
            || ' % of people are OK and'  || 
            attribute(
                get_feature(@layer,'city_name', @element),
                'people_not_ok'
            )
            ||  ' % are not'
        ),
        delimiter:= '\n' 
    )
)

Use this expression:

with_variable(
    'county',
    county_name,
    array_to_string(
        array_foreach(
            array_agg (
                city_name, 
                filter:="county_name"=@county
            ),
            @element 
            || ': '  || 
            attribute(
                get_feature(@layer,'city_name', @element),
                'people_ok'
            )  
            || ' % of people are OK and'  || 
            attribute(
                get_feature(@layer,'city_name', @element),
                'people_not_ok'
            )
            ||  ' % are not'
        ),
        delimiter:= '\n' 
    )
)

If you have everything on one layer (as it seems to be the case), you should use aggregate functions and filter the aggregated city_names by conty_name to create an array with all cities in a county using array_agg() function. From this array, loop through each element (city) to get the respective attribute values for the fiels people_ok and people_not_ok.

See the expression below.

enter image description here

with_variable(
    'county',
    county_name,
    array_to_string(
        array_foreach(
            array_agg (
                city_name, 
                filter:="county_name"=@county
            ),
            @element 
            || ': '  || 
            attribute(
                get_feature(@layer,'city_name', @element),
                'people_ok'
            )  
            || ' % of people are OK and'  || 
            attribute(
                get_feature(@layer,'city_name', @element),
                'people_not_ok'
            )
            ||  ' % are not'
        ),
        delimiter:= '\n' 
    )
)
Source Link
Babel
  • 74.9k
  • 15
  • 87
  • 227
Loading