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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
Anonymous
Not applicable

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

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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