Workspace capacity: Subsets Calc / Applies To

Hello Anaplanners,

I'm currently working on a model of workspace simulator of another Model.

I'm having some difficulties to find an optimum way of :

  1. Splitting my “Applies To” - I cant find a formula to help split the Dimensions which are in the following state; “Dim01, Dim02, Dim03” I want to have each dimension in a column (Line Item). Currently, i use Excel to delimit by comma then import the Data in Anaplan. Is there a better way of obtaining the dimensions in each column?
  2. Line Item Subsets and List subsets - Is there a way to obtain the subsets with their item count?

Your assistance will be much appreciated and each suggestions count ;)

Thanking you in advance,

Irish

Answers

  • Nico
    edited March 2023

    • I have maybe a solution that would help you drive the count.
    • 1. If you have a list with all your list then if you cross Line items x Dimension, you can have a boolean as :
      FIND("List Name","Applies to") <> 0 → If this boolean is TRUE, then your list name is in your applies to.

    • 2. You could drive the count in the properties modules with the formula : ISNOTBLANK(FINDITEM("ITEM Name","Subset Name")) → If this boolean is TRUE, then your list item is in your subset.
  • Thank you for your reply Nico.

    I cannot use the model as it is in production.

    However i can create a copy but it can cause inconveniences.

  • Are you familiar with APIs? The transactional metadata API can help you get the information about the model structure that you are looking for. You can start here for more background:

  • @Irish did you manage to achieve what you were looking for ? I think I can help with point 1) but for point 2) the options I'm thinking at are too "involved" @ryan_kohn , thanks for sharing the link to the APIs articles.

    I had a very quick look at the guide as well and I'm not sure I could find if and how to retrieve the counts for both List Subsets and Line Item Subsets…is it possible to easily do that via Trans APIs ? I did use postman in the past to retrieve the list of revision tags and all its info from models but I forgot most of it.

    Is there any quick how to video, article, etc that could help me with that ? Or a 10 mins call perhaps ? :´-)

    Thanks!

  • @Alessio_Pagliano

    List subset sizes are not directly available via the API, but it is possible to get the necessary information via API.

    Conceptually:

    1. Use the /lists endpoint to generate a list of all Lists
    2. Use the /lists/{listId} endpoint to get the details of a specific list
      1. This includes the current size of the list (in the itemCount attribute)
      2. This includes a list of any subsets along with their list IDs (in the subsets attributes)
    3. Use the /dimensions/{listId}/items with the subset list ID endpoint to generate a list of all the items in the subset
    4. In your script, you can count the items that are generated from the output of (3)

    For line item subsets, I don't believe there is an endpoint for getting a full list. However, if you already know the dimension ID for the line item subset, you can use the /dimensions/{listId}/items endpoint (as indicated in Step 3 above) to generate a list of items in the line item subset. It is possible to find the line item subset ID if you use the line item metadata endpoints to get the appliesTo for a line item that you know to be dimensioned by that line item subset.

    The details of each call are available in the API documentation: https://anaplanbulkapi20.docs.apiary.io/#/introduction/transactional-api-index

  • @ryan_kohn

    Thanks a lot for all these pointers : very helpful. I'm making slowly but steady progress.

    I could complete step 1,2 and 3. I am now stuck on step 4 where I would need to prepare a script to take the list of all the required IDs and return me the count. I did lookup a couple of script walkthroughts on youtube but it didn't work.

    If you/anyone could share any specific easy to follow links/videos that could help me to unlock this last step, it would be great !

    PS I have also upvoted for this Idea Exchange. I feel this type of report should be made available out of the box, now more than ever :-P

  • ryan_kohn
    edited August 2023

    @Alessio_Pagliano I actually recently went through this process recently and wrote a python script that handles steps 3 and 4 in my prior comment. Hope it helps!

    import logging
    import csv
    import requests
    
    # Logging config
    logging.basicConfig(level=logging.INFO)
    _logger = logging.getLogger(__name__)
    
    workspaceId = "8a88807f9a"
    modelId = "0FED08BFA32D"
    
    outputFilename="subset_details.csv"
    
     ## This script assumes you already have an auth token returned from a prior authentication call. If not, you will need to add extra code to authenticate.
    anaplan_token = "bahbas6512sdfvs"
    request_headers = {
        "Authorization": "AnaplanAuthToken {}".format(anaplan_token),
        "Accept": "application/json"
    }
    
     ## This script assumes you have already generated a list of listIds of all the subsets. If not, you will need to add extra code to generate this list.
    listsWithSubsets = [101000000019,101000000016]
    
    subsets = [] # Initialize the subsets array to be populated by the below code
    for l in listsWithSubsets:
        _logger.info(f"Sending metadata request for list {l}.")
        r_getListDetails = f"https://api.anaplan.com/2/0/workspaces/{workspaceId}/models/{modelId}/lists/{l}"
        r = requests.get(url=r_getListDetails, headers=request_headers)
        data = r.json()
    
        _logger.debug(f"Response with metadata:\n{data['metadata']}")
        listId = data['metadata']['id']
        listName = data['metadata']['name']
        subsetList = data['metadata']['subsets']
    
        _logger.info(f"{len(subsetList)} subsets found for list {l}. Getting subset details.")
        for s in subsetList:
            subset = {}
            subset['listId'] = listId
            subset['listName'] = listName
            subset['id'] = s['id']
            subset['name'] = s['name']
            r_getListItems = f"https://api.anaplan.com/2/0/workspaces/{workspaceId}/models/{modelId}/dimensions/{subset['id']}/items"
            r = requests.get(url=r_getListItems, headers=request_headers)
            data = r.json()
            subset['count'] = 0
            if "items" in data:
                subset['count'] = len(data['items'])
            _logger.info(f"{subset['count']} items found. Appending to list.")
            subsets.append(subset)
    
    _logger.info(f"Contents of the 'subsets' array: {subsets}")
    
    _logger.info(f"Generating csv file '{outputFilename}'")
    with open(outputFilename, 'w', newline='') as f:
        writer = csv.writer(f, quoting=csv.QUOTE_ALL)
        writer.writerow(['List Id','List Name','Subset Id','Subset Name','Item Count'])
        for s in subsets:
            writer.writerow([s['listId'],s['listName'],s['id'],s['name'],s['count']])
    
    

  • @ryan_khon, you are a legend :-)

    I will try it as soon as I can.