Reputation: 65
I am having issues trying to aggregate data with multiple conditions in PowerBI Dax.
I have a PowerBI Dataset similar to the one below, which lists Call ID and multiple vehicle codes and am trying to create a measure that acts as a flag using the logic below:
Dataset:
Result:
Any help or advise would be much appreciated. Thanks
Upvotes: 1
Views: 324
Reputation: 2615
Please try this code:
H HX Flag =
VAR H_List =
CALCULATETABLE ( VALUES ( TTable[CALLID] ), TTable[VEHICLE_CODE] = "H" )
VAR HX_List =
CALCULATETABLE ( VALUES ( TTable[CALLID] ), TTable[VEHICLE_CODE] = "HX" )
RETURN
COUNTX ( INTERSECT ( H_List, HX_List ), [CALLID] )
If we test it:
Do not forget to click the down-pointing arrow on CALLID column and ensure that "show items with no data" is checked. See the below picture:
Upvotes: 2
Reputation: 9052
Try this measure:
H HX Flag =
VAR T1 =
SUMMARIZE(
'Table',
'Table'[CALLID],
"Flag",
INT(
COUNTROWS( FILTER( 'Table', 'Table'[VEHICLE_CODE] IN { "H", "HX" } ) ) = 2
)
)
RETURN
IF( HASONEVALUE( 'Table'[CALLID] ), MINX( T1, [Flag] ), SUMX( T1, [Flag] ) )
The subtotal will give you the number of IDs flagged.
Upvotes: 0