# Invert the current selections

Invert the current selections by using the [SelectExcluded method](https://help.qlik.com/en-US/sense-developer/May2026/Subsystems/EngineJSONAPI/Content/service-field-selectexcluded.htm).

## Example

[](https://help.qlik.com/en-US/sense-developer/Subsystems/EngineAPI/Content/Sense_EngineAPI/DiscoveringAndAnalysing/MakeSelections/invert-current-selections.htm)

#### The goal is to invert the current selections in a field.

1. Create a hypercube with one dimension (qFieldDefs is Country) and one measure (qDef is Sum(Holes)).

The client sends:

```
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "CreateSessionObject",
  "handle": 1,
  "params": [
    {
      "qInfo": {
        "qId": "",
        "qType": "Chart"
      },
      "qHyperCubeDef": {
        "qStateName": "$",
        "qDimensions": [
          {
            "qLibraryId": "",
            "qNullSuppression": false,
            "qDef": {
              "qGrouping": "N",
              "qFieldDefs": [
                "Country"
              ],
              "qFieldLabels": [
                "Country label"
              ]
            }
          },
          {
            "qLibraryId": "",
            "qNullSuppression": false,
            "qDef": {
              "qGrouping": "N",
              "qFieldDefs": [
                ""
              ],
              "qFieldLabels": [
                ""
              ]
            }
          }
        ],
        "qMeasures": [
          {
            "qLibraryId": "",
            "qSortBy": {
              "qSortByState": 0,
              "qSortByFrequency": 0,
              "qSortByNumeric": 0,
              "qSortByAscii": 0,
              "qSortByLoadOrder": 1,
              "qSortByExpression": 0,
              "qExpression": {
                "qv": ""
              }
            },
            "qDef": {
              "qLabel": "",
              "qDescription": "",
              "qTags": [
                "tags"
              ],
              "qGrouping": "N",
              "qDef": "Sum(Holes)"
            }
          }
        ],
        "qInitialDataFetch": [
          {
            "qTop": 0,
            "qLeft": 0,
            "qHeight": 3,
            "qWidth": 1
          },
          {
            "qTop": 0,
            "qLeft": 0,
            "qHeight": 0,
            "qWidth": 0
          },
          {
            "qTop": 0,
            "qLeft": 0,
            "qHeight": 0,
            "qWidth": 0
          }
        ]
      }
    }
  ]
}
```

The engine returns:

```
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "qReturn": {
      "qType": "GenericObject",
      "qHandle": 2
    }
  },
  "change": [
    2
  ]
}
```

The hypercube is created and the handle is 2.

2. Select the first value in the hypercube.

The client sends:

```
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "SelectHyperCubeCells",
  "handle": 2,
  "params": [
    "/qHyperCubeDef",
    [
      0
    ],
    [
      0
    ],
    false
  ]
}
```

The engine returns:

```
{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "qSuccess": true
  },
  "change": [
    2
  ]
}
```

The selection operation is successful.

3.Get the layout of the hypercube.

The client sends:

```
{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "GetLayout",
  "handle": 2,
  "params": []
}
```

The engine returns:

{ "jsonrpc": "2.0", "id": 2, "result": { "qLayout": { "qInfo": { "qId": "91d405e4-d218-4c24-aa16-68d0fadfa078", "qType": "Chart" }, "qSelectionInfo": {}, "qHyperCube": { "qStateName": "$", "qSize": { "qcx": 2, "qcy": 1 }, "qDimensionInfo": [ { "qFallbackTitle": "Country label", "qApprMaxGlyphCount": 14, "qCardinal": 22, "qSortIndicator": "N", "qGroupFallbackTitles": [ "Country label" ], "qGroupPos": 0, "qStateCounts": { "qLocked": 0, "qSelected": 1, "qOption": 0, "qDeselected": 0, "qAlternative": 21, "qExcluded": 0, "qSelectedExcluded": 0, "qLockedExcluded": 0 }, "qTags": [ "$ascii", "$text" ], "qDimensionType": "D", "qGrouping": "N", "qNumFormat": { "qType": "R", "qnDec": 14, "qUseThou": 1, "qFmt": "##############", "qDec": ".", "qThou": "," }, "qIsAutoFormat": true, "qGroupFieldDefs": [ "Country" ] }, { "qApprMaxGlyphCount": 0, "qCardinal": 0, "qSortIndicator": "N", "qGroupFallbackTitles": [ "" ], "qGroupPos": 0, "qStateCounts": { "qLocked": 0, "qSelected": 0, "qOption": 0, "qDeselected": 0, "qAlternative": 0, "qExcluded": 0, "qSelectedExcluded": 0, "qLockedExcluded": 0 }, "qTags": [], "qError": { "qErrorCode": 7000 }, "qDimensionType": "D", "qGrouping": "N", "qNumFormat": { "qType": "U", "qnDec": 10, "qUseThou": 0 }, "qGroupFieldDefs": [ "" ] } ], "qMeasureInfo": [ { "qFallbackTitle": "Sum(Holes)", "qApprMaxGlyphCount": 6, "qCardinal": 0, "qSortIndicator": "A", "qNumFormat": { "qType": "U", "qnDec": 0, "qUseThou": 0 }, "qMin": 295317, "qMax": 295317, "qIsAutoFormat": true, "qAttrExprInfo": [] } ], "qEffectiveInterColumnSortOrder": [ 0, 2 ], "qGrandTotalRow": [ { "qText": "295317", "qNum": 295317, "qElemNumber": -1, "qState": "X", "qIsTotalCell": true } ], "qDataPages": [ { "qMatrix": [ [ { "qText": "United States", "qNum": "NaN", "qElemNumber": 0, "qState": "S" } ] ], "qTails": [ { "qUp": 0, "qDown": 0 } ], "qArea": { "qLeft": 0, "qTop": 0, "qWidth": 1, "qHeight": 1 } }, { "qMatrix": [], "qTails": [], "qArea": { "qLeft": 0, "qTop": 0, "qWidth": 0, "qHeight": 0 } }, { "qMatrix": [], "qTails": [], "qArea": { "qLeft": 0, "qTop": 0, "qWidth": 0, "qHeight": 0 } } ], "qPivotDataPages": [], "qStackedDataPages": [], "qMode": "S", "qNoOfLeftDims": -1 } } } }

The value United States is selected. There is 1 selected value (qSelected is 1) and 21 alternative values (qAlternative is 21).

4. Get the handle of the field Country.

The client sends:

{ "jsonrpc": "2.0", "id": 4, "method": "GetField", "handle": 1, "params": [ "Country" ] }

The engine returns:

{ "jsonrpc": "2.0", "id": 4, "result": { "qReturn": { "qType": "Field", "qHandle": 3 } } }

The handle of the field Country is 3.

4. Select all alternative values of the field Country.The handle of the request is 3 because the field has 3 as a handle.

The client sends:

{ "jsonrpc": "2.0", "id": 5, "method": "SelectAlternative", "handle": 3, "params": [ false ] }

The engine returns:

{ "jsonrpc": "2.0", "id": 5, "result": { "qReturn": true }, "change": [ 1, 2, 3 ] }

The selection is successful.

5. Get the layout of the hypercube.

The client sends:

{ "jsonrpc": "2.0", "id": 6, "method": "GetLayout", "handle": 2, "params": [] }

The engine returns:

{ "jsonrpc": "2.0", "id": 6, "result": { "qLayout": { "qInfo": { "qId": "91d405e4-d218-4c24-aa16-68d0fadfa078", "qType": "Chart" }, "qSelectionInfo": {}, "qHyperCube": { "qStateName": "$", "qSize": { "qcx": 2, "qcy": 21 }, "qDimensionInfo": [ { "qFallbackTitle": "Country label", "qApprMaxGlyphCount": 14, "qCardinal": 22, "qSortIndicator": "N", "qGroupFallbackTitles": [ "Country label" ], "qGroupPos": 0, "qStateCounts": { "qLocked": 0, "qSelected": 21, "qOption": 0, "qDeselected": 0, "qAlternative": 1, "qExcluded": 0, "qSelectedExcluded": 0, "qLockedExcluded": 0 }, "qTags": [ "$ascii", "$text" ], "qDimensionType": "D", "qGrouping": "N", "qNumFormat": { "qType": "R", "qnDec": 14, "qUseThou": 1, "qFmt": "##############", "qDec": ".", "qThou": "," }, "qIsAutoFormat": true, "qGroupFieldDefs": [ "Country" ] }, { "qApprMaxGlyphCount": 0, "qCardinal": 0, "qSortIndicator": "N", "qGroupFallbackTitles": [ "" ], "qGroupPos": 0, "qStateCounts": { "qLocked": 0, "qSelected": 0, "qOption": 0, "qDeselected": 0, "qAlternative": 0, "qExcluded": 0, "qSelectedExcluded": 0, "qLockedExcluded": 0 }, "qTags": [], "qError": { "qErrorCode": 7000 }, "qDimensionType": "D", "qGrouping": "N", "qNumFormat": { "qType": "U", "qnDec": 10, "qUseThou": 0 }, "qGroupFieldDefs": [ "" ] } ], "qMeasureInfo": [ { "qFallbackTitle": "Sum(Holes)", "qApprMaxGlyphCount": 5, "qCardinal": 0, "qSortIndicator": "A", "qNumFormat": { "qType": "U", "qnDec": 0, "qUseThou": 0 }, "qMin": 36, "qMax": 36968, "qIsAutoFormat": true, "qAttrExprInfo": [] } ], "qEffectiveInterColumnSortOrder": [ 0, 2 ], "qGrandTotalRow": [ { "qText": "66399", "qNum": 66399, "qElemNumber": -1, "qState": "X", "qIsTotalCell": true } ], "qDataPages": [ { "qMatrix": [ [ { "qText": "Denmark", "qNum": "NaN", "qElemNumber": 1, "qState": "S" } ], [ { "qText": "Spain", "qNum": "NaN", "qElemNumber": 2, "qState": "S" } ], [ { "qText": "Canada", "qNum": "NaN", "qElemNumber": 3, "qState": "S" } ] ], "qTails": [ { "qUp": 0, "qDown": 0 } ], "qArea": { "qLeft": 0, "qTop": 0, "qWidth": 1, "qHeight": 3 } }, { "qMatrix": [], "qTails": [], "qArea": { "qLeft": 0, "qTop": 0, "qWidth": 0, "qHeight": 0 } }, { "qMatrix": [], "qTails": [], "qArea": { "qLeft": 0, "qTop": 0, "qWidth": 0, "qHeight": 0 } } ], "qPivotDataPages": [], "qStackedDataPages": [], "qMode": "S", "qNoOfLeftDims": -1 } } } }

All values in the field Country are selected except United States, which became an alternative value.

There are 21 selected values (qSelected is 21) and 1 alternative value (qAlternative is 1).

6. Invert the current selections in the field Country.The handle of the request is 3 because the field has 3 as a handle.

The client sends:

{ "jsonrpc": "2.0", "id": 7, "method": "SelectExcluded", "handle": 3, "params": [ false ] }

The engine returns:

{ "jsonrpc": "2.0", "id": 7, "result": { "qReturn": true }, "change": [ 2, 3 ] }

The selection is successful.

7. Get the layout of the hypercube.

The client sends:

{ "jsonrpc": "2.0", "id": 8, "method": "GetLayout", "handle": 2, "params": [] }

The engine returns:

{ "jsonrpc": "2.0", "id": 8, "result": { "qLayout": { "qInfo": { "qId": "9aa12a47-346f-40be-9c6d-250100d54034", "qType": "Chart" }, "qMeta": {}, "qSelectionInfo": {}, "qHyperCube": { "qStateName": "$", "qSize": { "qcx": 2, "qcy": 1 }, "qDimensionInfo": [ { "qFallbackTitle": "Country label", "qApprMaxGlyphCount": 14, "qCardinal": 22, "qSortIndicator": "N", "qNumFormat": { "qType": "R", "qnDec": 14, "qUseThou": 1, "qFmt": "##############", "qDec": ".", "qThou": "," }, "qIsAutoFormat": true, "qGroupFallbackTitles": [ "Country label" ], "qGroupPos": 0, "qStateCounts": { "qLocked": 0, "qSelected": 1, "qOption": 0, "qDeselected": 0, "qAlternative": 21, "qExcluded": 0, "qSelectedExcluded": 0 }, "qTags": [ "$ascii", "$text" ], "qDimensionType": "D", "qGrouping": "N" }, { "qApprMaxGlyphCount": 0, "qCardinal": 0, "qSortIndicator": "N", "qNumFormat": { "qType": "U", "qnDec": 10, "qUseThou": 0 }, "qGroupFallbackTitles": [ "" ], "qGroupPos": 0, "qStateCounts": { "qLocked": 0, "qSelected": 0, "qOption": 0, "qDeselected": 0, "qAlternative": 0, "qExcluded": 0, "qSelectedExcluded": 0 }, "qTags": [], "qError": { "qErrorCode": 7000 }, "qDimensionType": "D", "qGrouping": "N" } ], "qMeasureInfo": [ { "qFallbackTitle": "Sum(Holes)", "qApprMaxGlyphCount": 6, "qCardinal": 1, "qSortIndicator": "A", "qNumFormat": { "qType": "U", "qnDec": 0, "qUseThou": 0 }, "qIsAutoFormat": true, "qMin": 295317, "qMax": 295317 } ], "qEffectiveInterColumnSortOrder": [ 0, 2 ], "qGrandTotalRow": [ { "qText": "295317", "qNum": 295317, "qElemNumber": -1, "qState": "X", "qIsTotalCell": true } ], "qDataPages": [ { "qMatrix": [ [ { "qText": "United States", "qNum": "NaN", "qElemNumber": 0, "qState": "S" } ] ], "qTails": [ { "qUp": 0, "qDown": 0 } ], "qArea": { "qLeft": 0, "qTop": 0, "qWidth": 1, "qHeight": 1 } }, { "qMatrix": [], "qTails": [], "qArea": { "qLeft": 0, "qTop": 0, "qWidth": 0, "qHeight": 0 } }, { "qMatrix": [], "qTails": [], "qArea": { "qLeft": 0, "qTop": 0, "qWidth": 0, "qHeight": 0 } } ], "qPivotDataPages": [], "qStackedDataPages": [], "qMode": "S" } } } }

The selections are inverted.

There is 1 selected value (qSelected is 1) and 21 alternative values (qAlternative is 21).