Get list of streams

Hello,

I am using the powerBI connector to view and analyse simulation results which are carried out in grasshopper. It works very well, however I was hoping to make it easier for users to change which speckle model they would like to analyse. Currently you have to go into the query and edit the source link.

My thinking was to get a list of all the streams on a users account and then use a parameter to feed back into the source which would allow the user to select which one they want to analyse.

Is there a way I could get a list of available streams on an account in powerBI?

Thanks

Great question—and yes, this is definitely possible with some setup in Power BI and Power Query!

You’re editing the query manually to change the Speckle model URL. But you want users to select a project and model from a dropdown or slicer and then have Power BI dynamically fetch and display the results.

1. Query all projects and models from your Speckle account
You can use a GraphQL query to fetch projects and their models. In Power Query, you’d run that via a function made available by the latest data connector: speckleApiFetch , which makes a custom call to https:// SERVER_URL /graphql and turns it into a table for use in reports.

Begin a new blank Query:

let query = """
   query GetUserProjectAndModels() {
      activeUser {
          projects(filter: $filter) {
            items {
              id
              description
              name
              role
              models {
                items {
                  id
                  name
              }
           }
        }
    }
   """,
   variables = [ ],
   response = speckleApiFetch( SERVER_URL , query, variables)
in
   response

Rename this query ProjectAndModels

2. Create a hierarchical slicer in Power BI

  • Load the projects & models table.
  • Add a slicer with Project Name and Model Name to allow users to drill down.

3. Build a dynamic URL based on user selection

  • Create a DAX measure:
SelectedModelUrl = 
VAR ProjectID = SELECTEDVALUE('ProjectAndModels'[Project ID])
VAR ModelID = SELECTEDVALUE('ProjectAndModels'[Model ID])
RETURN 
IF(NOT(ISBLANK(ProjectID)) && NOT(ISBLANK(ModelID)), 
   "https://app.speckle.systems/projects/" & ProjectID & "/models/" & ModelID, 
   BLANK()
)

4. Use that dynamic URL in Power Query

  • In Power Query, set up a parameter and use it in your main data call:
let
    selectedUrl = SelectedModelUrl ,  // This is your dynamic parameter
    data = if selectedUrl <> "" then Speckle.GetByUrl(selectedUrl) else null
in
    data

This may introduce new concepts to your Power BI arsenal, so bear with it and let me know if my memory has failed me or if something isn’t quite working or clear enough. We are also making changes to the Power BI connector so I’ll try to make sure this stays up to date.

1 Like

In addition to jonathon’s response, you can also use Power BI parameters. More on that:

You can store have a list of model URLs and reference this parameter in the query.

1 Like

Depends on how dynamic you want to be :smiley:

DynamicStrategiesPrincipalResonanceGIF

As always - a prompt and very helpful response. Lots of new concepts indeed!

I didn’t get the exact code to work in power query. On replacing the “SERVER_URL” with the speckle server I get the below error.

I then add an additional / and get a different error.

Any idea what’s going on here - or have I got the complete wrong end of the stick?

Looks for sure like it is sensitive to trailing /. For the prior error id double check the values of query and variables

Great thank you!

This seemed to be an issue with the query so I ended up embedding this directly inside Speckle.Api.Fetch which solved this.

It feels like I’m almost there. The last bit I’m getting stuck on is how I can link the DAX measure (which correctly reports the url) with the #SpeckleUrl parameter? Currently there is nothing that is telling the parameter to update based on the slicer selection. I can’t find any solutions elsewhere to this one.

Apologies @davidjbrownstein, I have corrected step 4:

SelectedModelUrl in place of #SpeckleUrl


It is worth mentioning this will need a refresh of the data when the slicer value changes because the Speckle Data Connector isn’t set up for DirectConnection or whichever mode is named.


it could also be the case that @gokermu’s suggestion is just simpler :man_shrugging:

1 Like