2

What's wrong in the below code

DEFINE
MEASURE DimDate[MyMeasure] = 
    COUNTROWS(DimDate)

EVALUATE DimDate[MyMeasure]

I'm getting the following error while running the query:

Query (1, 1) The expression specified in the query is not a valid table expression

dybzon
  • 1,236
  • 2
  • 15
  • 21
MeBy2
  • 21
  • 9
  • I'm getting the following error while running the query, Query (1, 1) The expression specified in the query is not a valid table expression. – MeBy2 Aug 07 '17 at 09:11

1 Answers1

3

Your DAX query must evaluate to a table when you are using DAX as a query language.

E.g. this query is valid because it returns a table with one column and one row:

DEFINE MEASURE DimDate[MyMeasure] = COUNTROWS(DimDate)
EVALUATE
ROW("MyColumn", DimDate[MyMeasure])

But this query will fail because it returns a scalar value instead of a table:

DEFINE MEASURE DimDate[MyMeasure] = COUNTROWS(DimDate)
EVALUATE DimDate[MyMeasure]

You can find the syntax documentation from Microsoft here.

Please note that this is different from defining measures or calculated columns inside a tabular model. Expressions for measures or calculated columns should always evaluate to a scalar value.

dybzon
  • 1,236
  • 2
  • 15
  • 21
  • yuuup dude just like charm,And I can't upvote your answer i don't enough reputation – MeBy2 Aug 08 '17 at 04:39
  • Can you tell what function return scalar values and what function will return tables – MeBy2 Aug 08 '17 at 04:40
  • Cool. Please mark it as the answer if it solved your issue. Then others can benefit from it too. In Microsofts documentation they should always state what the return type of a function is. When you use DAX as a query language the final result should be a table - kind of like when you use SQL as a query language. – dybzon Aug 08 '17 at 04:47
  • cool bro,Actually I'm very new to the tabular model and DAX query so any suggestion from your side – MeBy2 Aug 08 '17 at 04:53
  • I'll try to add some more details to the answer later, to explain this even better – dybzon Aug 08 '17 at 05:00