Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
chrisha
Frequent Visitor

Can't read scalar values using ADOMD.NET in Analysis Services/Power BI model

Hi all, and apologies if this is the wrong forum for this.


I'm trying to connect to a local analysis services instance using ADOMD.NET. Querying for tabular data works with no problems, but I'd like to be able to execute measures stored in the model and retrieve the result.


I've tried many different variations over the same theme, but the code below represents the essentials. Trying any measure using this code will result in a generic error telling me that the "Specified method is not supported." As far as I can tell this will happen on the executeScalar call regardless of what DAX code I pass to it.


Am I doing something fundamentally wrong here, or is this a limitation of ADOMD.NET? If so, is there a way to execute DAX on the model using another framework?

 

 

using (var connection = new AdomdConnection(_connectionString))
{
  connection.Open();

  AdomdCommand cmd = new AdomdCommand(query);
  cmd.Connection = connection;

  cmd.ExecuteScalar();
  data = (string)cmd.ExecuteScalar();
}

 

 

 

1 ACCEPTED SOLUTION

Sorry, this is not a good solution as it runs SQL instead of DAX. I did find a workaround by wrapping measure-DAX in a ROW()-call so that the data would be returned as a table with one row.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

HI @chrisha,

According to your description, I think you are working with the c# programming language and try to connect the AS data source with a custom command.
If that is the case, I think you need to use the t-SQL query instead of the DAX query which you used in the connection. (As the document mention, SQL command not supported DAX expression)

SqlCommand.ExecuteScalar Method 

AdomdCommand Constructors 

using (var connection = new AdomdConnection(_connectionString))
{
	connection.Open();
	string query="SELECT * FROM TABLE";
	AdomdCommand cmd = new AdomdCommand(query);
	cmd.Connection = connection;
	cmd.ExecuteScalar();
	data = (string)cmd.ExecuteScalar();
}

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Sorry, this is not a good solution as it runs SQL instead of DAX. I did find a workaround by wrapping measure-DAX in a ROW()-call so that the data would be returned as a table with one row.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.