Forum Discussion
JavierLopezFALP
1 year agoFrequent Visitor
DAX Calculated Column with "variable tables" as variables.
Greetings I'm attempting to create a calculated column that brings out a result based on the rowscount form another table. The relation is ONLY the id of each individual. The following illustrate...
- 1 year ago
The variable
tableis the source of the error, sinceIFmust always return a scalar value.In the below expression, the 2nd and 3rd arguments are table rather than scalar values:
var table = if(countrows(table2) < 1, table1, table2)One way around this is to rewrite as follows:
column = --[state] can adopt values 1 to 5, and there are blank values. VAR table1 = FILTER ( RELATEDTABLE ( table2 ), NOT ( ISBLANK ( [state] ) ) ) VAR table2 = FILTER ( RELATEDTABLE ( table2 ), [state] IN { 1, 2 } ) VAR selectTable1 = COUNTROWS ( table2 ) < 1 VAR table = UNION ( FILTER ( table1, selectTable1 ), FILTER ( table2, NOT selectTable1 ) ) ...Does this work as intended?
techies
Super User
1 year agoHi JavierLopezFALP please try this calculated column
HasRelevantAppointment =
VAR HasState1Or2 =
COUNTROWS(
FILTER(
RELATEDTABLE(Appointments_ServiceB),
[State] IN {1, 2}
)
) > 0
VAR FilteredRows =
FILTER(
RELATEDTABLE(Appointments_ServiceB),
IF(HasState1Or2, [State] IN {1, 2}, NOT(ISBLANK([State])))
)
VAR ValidRows =
FILTER(
FilteredRows,
[Date] >= DATE(2024,1,1) && [Date] < DATE(2024,4,1)
)
RETURN
IF(COUNTROWS(ValidRows) > 0, "YES", "NO")