Forum Discussion
cell magic %%dax returning error
Hi,
I noticed a syntax error in my previously supplied code and I've tried using fabric.evaluate_dax() as you suggest:
df_dax = fabric.evaluate_dax(
dataset = "REDACTED", \
workspace = "REDACTED", \
dax_string =
"""
EVALUATE
SUMMARIZECOLUMNS (
'dim_date'[calendar_start_of_week],
'dim_ga_session'[ga_page_path_session_landing],
'dim_ga_session'[ga_is_login_session],
'dim_ga_session'[ga_channel],
'dim_ga_session'[ga_site_variant],
FILTER (
KEEPFILTERS ( VALUES ( 'dim_date'[calendar_start_of_week] ) ),
'dim_date'[calendar_start_of_week] >= DATE ( 2014, 1, 1 )
),
TREATAS ( { "Canada" }, 'dim_ga_session'[ga_site_variant] ),
"sessions", 'model_metrics'[# Sessions],
"bounce_sessions", 'model_metrics'[# Bounce Sessions]
)
"""
)
However this code still generates an error:
---------------------------------------------------------------------------
NotSupportedException Traceback (most recent call last)
NotSupportedException: type System.Object is not supported
at Parquet.Schema.DataField..ctor(String name, Type clrType, Nullable`1 isNullable, Nullable`1 isArray, String propertyName)
at Parquet.Schema.DataField`1..ctor(String name, Nullable`1 nullable)
The above exception was the direct cause of the following exception:
TargetInvocationException Traceback (most recent call last)
TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.NotSupportedException: type System.Object is not supported
at Parquet.Schema.DataField..ctor(String name, Type clrType, Nullable`1 isNullable, Nullable`1 isArray, String propertyName)
at Parquet.Schema.DataField`1..ctor(String name, Nullable`1 nullable)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at Microsoft.Fabric.SemanticLink.ParquetWriter.GetFields(AdomdDataReader reader)
at Microsoft.Fabric.SemanticLink.ParquetWriter.WriteAsync(AdomdDataReader reader)
at Microsoft.Fabric.SemanticLink.ParquetWriter.WriteAsync()
The above exception was the direct cause of the following exception:
AggregateException Traceback (most recent call last)
Cell In[43], line 1
----> 1 df_dax = fabric.evaluate_dax(
2 dataset = "REDACTED", \
3 workspace = "REDACTED", \
4 dax_string =
5 """
6 EVALUATE
7 SUMMARIZECOLUMNS (
8 'dim_date'[calendar_start_of_week],
9 'dim_ga_session'[ga_page_path_session_landing],
10 'dim_ga_session'[ga_is_login_session],
11 'dim_ga_session'[ga_channel],
12 'dim_ga_session'[ga_site_variant],
13 FILTER (
14 KEEPFILTERS ( VALUES ( 'dim_date'[calendar_start_of_week] ) ),
15 'dim_date'[calendar_start_of_week] >= DATE ( 2014, 1, 1 )
16 ),
17 TREATAS ( { "United Kingdom" }, 'dim_ga_session'[ga_site_variant] ),
18 "sessions", 'model_metrics'[# Sessions],
19 "bounce_sessions", 'model_metrics'[# Bounce Sessions]
20 )
21 """
22 )
File ~/cluster-env/clonedenv/lib/python3.10/site-packages/sempy/_utils/_log.py:269, in mds_log.<locals>.get_wrapper.<locals>.log_decorator_wrapper(*args, **kwargs)
266 raise
268 try:
--> 269 result = func(*args, **kwargs)
271 # The invocation for get_message_dict moves after the function
272 # so it can access the state after the method call
273 message.update(extractor.get_completion_message_dict(result, arg_dict))
File ~/cluster-env/clonedenv/lib/python3.10/site-packages/sempy/fabric/_flat.py:891, in evaluate_dax(dataset, dax_string, workspace, verbose)
869 """
870 Compute `DAX <https://learn.microsoft.com/en-us/dax/>`_ query for a given dataset.
871
(...)
888 :class:`~sempy.fabric.FabricDataFrame` holding the result of the DAX query.
889 """
890 client: DatasetXmlaClient = _get_or_create_workspace_client(workspace).get_dataset_client(dataset, mode=ConnectionMode.XMLA) # type: ignore
--> 891 return client.evaluate_dax(dax_string, verbose)
File ~/cluster-env/clonedenv/lib/python3.10/site-packages/sempy/fabric/_client/_base_dataset_client.py:103, in BaseDatasetClient.evaluate_dax(self, query, verbose)
87 def evaluate_dax(self, query: str, verbose: int = 0) -> FabricDataFrame:
88 """
89 Retrieve results of DAX query as a FabricDataFrame.
90
(...)
101 FabricDataFrame converted from the results of a DAX query.
102 """
--> 103 df = self._evaluate_dax(query, verbose)
104 return FabricDataFrame(df, dataset=self._dataset_name, workspace=self._workspace_client.get_workspace_name())
File ~/cluster-env/clonedenv/lib/python3.10/site-packages/sempy/fabric/_client/_dataset_xmla_client.py:68, in DatasetXmlaClient._evaluate_dax(self, query, verbose, batch_size)
67 def _evaluate_dax(self, query: str, verbose: int = 0, batch_size: int = 100000) -> pd.DataFrame:
---> 68 return self._get_DAX(dax_string=query, batch_size=batch_size, verbose=verbose)
File ~/cluster-env/clonedenv/lib/python3.10/site-packages/sempy/_utils/_log.py:269, in mds_log.<locals>.get_wrapper.<locals>.log_decorator_wrapper(*args, **kwargs)
266 raise
268 try:
--> 269 result = func(*args, **kwargs)
271 # The invocation for get_message_dict moves after the function
272 # so it can access the state after the method call
273 message.update(extractor.get_completion_message_dict(result, arg_dict))
File ~/cluster-env/clonedenv/lib/python3.10/site-packages/sempy/fabric/_client/_dataset_xmla_client.py:195, in DatasetXmlaClient._get_DAX(self, dax_string, batch_size, verbose)
193 df, fields = dax_to_parquet()
194 else:
--> 195 raise e
197 return self._convert_dtypes(df, fields)
File ~/cluster-env/clonedenv/lib/python3.10/site-packages/sempy/fabric/_client/_dataset_xmla_client.py:185, in DatasetXmlaClient._get_DAX(self, dax_string, batch_size, verbose)
182 pass
184 try:
--> 185 df, fields = dax_to_parquet()
186 except AdomdConnectionException:
187 # retry on connection error - examples include "The connection either timed out or was lost." or "The request was routed to the wrong node"
188 df, fields = dax_to_parquet()
File ~/cluster-env/clonedenv/lib/python3.10/site-packages/sempy/_utils/_log.py:269, in mds_log.<locals>.get_wrapper.<locals>.log_decorator_wrapper(*args, **kwargs)
266 raise
268 try:
--> 269 result = func(*args, **kwargs)
271 # The invocation for get_message_dict moves after the function
272 # so it can access the state after the method call
273 message.update(extractor.get_completion_message_dict(result, arg_dict))
File ~/cluster-env/clonedenv/lib/python3.10/site-packages/sempy/fabric/_client/_dataset_xmla_client.py:168, in DatasetXmlaClient._get_DAX.<locals>.dax_to_parquet()
166 try:
167 with self.get_adomd_connection() as adomd_connection:
--> 168 fields = ParquetWriter.DAXToParquet(
169 dax_string,
170 temp_file_name,
171 batch_size,
172 adomd_connection,
173 verbose
174 )
175 df = pd.read_parquet(temp_file_name)
176 return df, fields
AggregateException: One or more errors occurred. (Exception has been thrown by the target of an invocation.)
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.NotSupportedException: type System.Object is not supported
at Parquet.Schema.DataField..ctor(String name, Type clrType, Nullable`1 isNullable, Nullable`1 isArray, String propertyName)
at Parquet.Schema.DataField`1..ctor(String name, Nullable`1 nullable)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at Microsoft.Fabric.SemanticLink.ParquetWriter.GetFields(AdomdDataReader reader)
at Microsoft.Fabric.SemanticLink.ParquetWriter.WriteAsync(AdomdDataReader reader)
at Microsoft.Fabric.SemanticLink.ParquetWriter.WriteAsync()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at Microsoft.Fabric.SemanticLink.ParquetWriter.DAXToParquet(String dax, String fileName, Int32 batchSize, AdomdConnection adomdConnection, Int32 verbose)Hi mark_carlisle ,
It looks like there is some syntax issue - while working with FILTER and KEEPFILTERS.
Try to refer this Link - Using KEEPFILTERS in DAX - SQLBI inorder to debug your syntax issue.
Additional References -
Solved: 1. Diff between Filter() and KeepFilters() - Microsoft Fabric Community
Hope this is helpful. Please let me know incase of further queries.
- mark_carlisle2 years agoAdvocate IV
The DAX runs without issue in DAX Studio so unless you can highlight the specific syntax issue then I'm not confident your reply is correct.
I think the more likely issue is that theres some issue with how its been implemented in the fabric.evaluate_dax() function.
- Anonymous2 years agoNot applicable
Hi mark_carlisle ,
Apologies for the issue you have been facing. As you were able to execute DAX query without any issue, this might be problem with fabric.evaluate_dax() function.
This might require a deeper investigation from our engineering team and they can guide you better.
Please go ahead and raise a support ticket to reach our support team:
https://support.fabric.microsoft.com/support
Please provide the ticket number here as we can keep an eye on it.
Hope this is helpful. Please let me know incase of further queries.- Anonymous2 years agoNot applicable
Hello mark_carlisle ,
We haven’t heard from you on the last response and was just checking back to see if you got a chance to create a support ticket. If yes, please provide the ticket number here as we can keep an eye on it.