Forum Discussion
Many-to-Many Currency Conversion - DAX Error returning final result for Backlog measure
SQLMonger I hope this helps you. thank you.
The error you're encountering, "The expression specified in the query is not a valid table expression," typically occurs when you try to return a scalar value (a single number or text) from a measure, but DAX expects a table as the result. In your case, it's likely happening because you're trying to return a scalar value (Result) from your measure '[Backlog Amt]'.
To resolve this issue and get the expected result, you can follow these steps:
1. **Separate the Measure Calculation and Aggregation**: In your '[Backlog Amt]' measure, perform the calculation of 'AggregatedSalesInCurrency' but don't aggregate it in that measure. Instead, create a separate measure to perform the aggregation.
```DAX
MEASURE 'Sales Order'[Aggregated Backlog Amt] =
VAR _LastDateInRange =
CALCULATE(
MAX( Calendar[Date] ),
FILTER( ALL( 'Calendar' ), 'Calendar'[Date] = MAX( 'Calendar'[Date] ))
)
VAR AggregatedSalesInCurrency =
ADDCOLUMNS (
SUMMARIZE ('Sales Order',
'Source Currency'[Source Currency Code]
),
"@Backlog", [Loc Backlog] * LOOKUPVALUE(
'Currency Rate'[Rate] ,
'Currency Rate'[CalendarDate], _LastDateInRange,
'Currency Rate'[ToCurrencyCode], SELECTEDVALUE( 'Target Currency'[Target Currency] ),
'Currency Rate'[FromCurrencyCode], 'Source Currency'[Source Currency Code]
)
)
RETURN
AggregatedSalesInCurrency
```
2. **Create a Separate Aggregation Measure**: Now, create another measure to aggregate the 'AggregatedSalesInCurrency' and return the final result.
```DAX
MEASURE 'Sales Order'[Backlog Amt] =
IF (
NOT ( HASONEVALUE( 'Target Currency'[Target Currency Code] ) ),
ERROR( "Select a single Target Currency Code" ),
VAR AggregatedSalesInCurrency = [Aggregated Backlog Amt]
VAR Result = SUMX( AggregatedSalesInCurrency, [@Backlog] )
RETURN Result
)
```
By separating the calculation and aggregation into two measures, you can avoid the "The expression specified in the query is not a valid table expression" error, and your measure '[Backlog Amt]' should work correctly, returning the aggregated result as expected.