Hi. Question on Sort By attributes. I have my data...
# gooddata-cloud
s
Hi. Question on Sort By attributes. I have my data column - Product Type and my order column Product Type Order, both attributes in a dimension. I set Product Type Order as the sort for Product Type. Product Type Order is numeric, 1, 2, 3…10, 11, 12. However, the sort is running alpha: 1, 10, 11, 2. How do I get this to sort numerically - there doesn’t seem to be a way to indicate that that attribute is numeric.
m
Hi Sean, what data type is your sorting column? Is it integer or string? GoodData should sort numerically if the data type is integer and alphabetically if it is string. So one option would be to change the data type to integer (if it is not). The other option if you need it to be string for any reason, is to update the values of the string to be sorted alphabetically (‘001’, ‘002’, …)
j
Alternative to updating your data - you can create a SQL dataset and convert value of the column before mapping to attribute.
s
image.png
It’s already an integer
image.png
image.png
Sorts alpha
I have sortby set to that column already
Changing the Raw data isn’t great
m
I see, that does not seem correct behaviour. Could you please share more info, like the type of datasource database you are running this against, and the relevant part of the LDM JSON definition? To get this you can export the LDM to JSON (three dots icon in the top right of the modeller and export model to JSON). Only the part with the specific attribute should be enough. In my case it looks like this:
Copy code
"attributes": [
                    {
                        "id": "attr1",
                        "title": "Attr1",
                        "description": "Attr1",
                        "labels": [
                            {
                                "id": "attr1.attrint",
                                "title": "Attr Int",
                                "description": "",
                                "sourceColumn": "attr_int",
                                "sourceColumnDataType": "INT",
                                "tags": [
                                    "TEST order"
                                ],
                                "valueType": "TEXT"
                            },
                            {
                                "id": "attr1.attrstr",
                                "title": "Attr str",
                                "description": "",
                                "sourceColumn": "attr_str",
                                "sourceColumnDataType": "STRING",
                                "tags": [
                                    "TEST order"
                                ],
                                "valueType": "TEXT"
                            }
                        ],
                        "tags": [
                            "TEST order"
                        ],
                        "defaultView": {
                            "id": "attr1.attrint",
                            "type": "label"
                        },
                        "sourceColumn": "attr1",
                        "sourceColumnDataType": "STRING",
                        "sortDirection": "ASC",
                        "sortColumn": "attr_int"
                    }
                ]
s
{ “id”: “DIM_PROJECT.ESTIMATE_STATUS”, “title”: “Estimate Status”, “description”: “Estimate Status”, “labels”: [], “tags”: [ “Dim project” ], “sourceColumn”: “ESTIMATE_STATUS”, “sortDirection”: “ASC”, “sortColumn”: “ESTIMATE_STATUS_ORDER” },
It’s a Snowflake Datasource
m
Thanks Sean. Any ideas @Jan Soubusta? Do we know about any issues with sorting in Snowflake? Could it be some issue with outdated PDM?
j
Please, copy&paste here result of this call: <http://localhost:3000/api/v1/entities/dataSources/demo-test-ds/dataSourceTables/order_lines%7C&lt;your_host&gt;/api/v1/entities/dataSources/&lt;your_data_source_id&gt;/dataSourceTables&gt;/DIM_PROJECT I hope I guess the table name right from the attribute id prefix. Specifically, we need to see the column ESTIMATE_STATUS_ORDER and it's data type.
🙏 1
s
here is the result of that api call
(I work with @Sean Barry and have the information you need)
Here is the right environment file
It is a view by the way
{ "name": "ESTIMATE_STATUS_ORDER", "dataType": "INT", "isPrimaryKey": false, "referencedTableId": null, "referencedTableColumn": null },
is the specific field/property
j
So even GoodData thinks it is INTEGER. But still the sorting is done as it would be STRING, right? @Jan Kadlec sorting is happening in crosstab component. Any idea why the sorting could happen as it is STRING even though it is INTEGER?
j
Hi, Could you please clear caches and try it again? It should work now.
s
@Jan Kadlec Awesome, works great
Thanks for the help
j
Happy that it works! Sorry for the inconvenience.