function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Artsiom KazArtsiom Kaz 

Get specific record from dataset in SAQL Tableau

I have a dataset with records.
It is required to me to get specific record for calculations in SAQL.
Is there any function to get specific record in SAQL, like in map in apex.
For example: dataset.get(id).
VinayVinay (Salesforce Developers) 
You can reach out to Tableau CRM group on
https://trailhead.salesforce.com/trailblazer-community/groups/0F9300000009MBPCA2?tab=discussion for inputs on your ask.

Thanks,
Arlene BarrArlene Barr



Is there any function to get specific record in SAQL, like in map in apex.:

Try this:

Map<String, CustomObject__c> myMap = new Map<String, CustomObject__c>(); 
for(CustomObject__c objCS : [Select z.Name, z.Id From CustomObject__c z])
        myMap.put(objCS.Name, objCS);

 Make sure name is mandatory or put a condition that string name must not be blank before filling the object into map.
Hope it helps.
Arlene BarrArlene Barr
Map<String, CustomObject__c> myMap = new Map<String, 
CustomObject__c>([Select z.Name, z.Id From CustomObject__c z]);
The one that was flagged as correct by 'Admin' did what the OP explicitly asked not to do - loop through the list of records and add them to the Map one at a time.
You don't need to use the 'z' alias though.
https://www.onecognizant.net/
Arlene BarrArlene Barr
this still produces a Map with the Id as the key (albeit with the Id as a String type not an Id).
The order of the fields in the SOQL statement does not make a difference - when Apex casts the list to a Map it uses trhe Id as the Key.
In fact, you don't even need to include the Id as a field in the SOQL - I tried this with one of my Custom types and it works just fine, with the Id still be used as the Key:
Map<String, CustomType__c> myMap = 
    new Map<String, CustomType__c>([Select Name, Description__c From CustomType__c]);
system.debug(myMap);
So, it is NOT possible to do what the OP asked for - create a Map with the Name as the Key, without using a loop to iterate over the list and build the map one record at a time.
One Cognizant (https://www.onecognizant.one/)