Forum Discussion
khisla
Helper II
1 year agoDAX Command - IF variables, SWITCH and COALESCE
I need a DAX commend to identify the store to which an employee is based to sales commission calculation purposes Please find table of specific scenarios and expected results for each one. So I hav...
- 1 year ago
Hello khisla
You added one ) in your second condition in the CASE
Normally, the following measure should workNext= VAR EntranceStore = SELECTEDVALUE('HILAN'[Entrance Store]) VAR ExitStore = SELECTEDVALUE('HILAN'[Exit Store]) VAR DefaultStore = SELECTEDVALUE('HILAN'[Employee Default Store]) RETURN SWITCH( TRUE(), NOT(ISBLANK(EntranceStore)) && EntranceStore <> DefaultStore, EntranceStore, NOT(ISBLANK(ExitStore)) && ExitStore <> DefaultStore, ExitStore, NOT(ISBLANK(EntranceStore)) || EntranceStore = DefaultStore || ISBLANK(ExitStore) || ExitStore = DefaultStore, DefaultStore, DefaultStore )
Cookistador
Super User
1 year agoHi khisla
Normally, the following measure should return what you need
Store Result=
VAR EntranceStore = SELECTEDVALUE('Table'[Entrance Store])
VAR ExitStore = SELECTEDVALUE('Table'[Exit Store])
VAR DefaultStore = SELECTEDVALUE('Table'[Default Store])
RETURN
SWITCH(
TRUE(),
EntranceStore<>"" && EntranceStore <> DefaultStore, EntranceStore,
ExitStore<>"" && ExitStore <> DefaultStore, ExitStore,
EntranceStore<>"" || EntranceStore = DefaultStore || ExitStore="" || ExitStore = DefaultStore, DefaultStore,
DefaultStore
)
If it is not working for you (probably due to the copy/paste I did), you have to replace <> "" by not(isblank()
So the formula would come
Next =
VAR EntranceStore = SELECTEDVALUE('Table'[Entrance Store])
VAR ExitStore = SELECTEDVALUE('Table'[Exit Store])
VAR DefaultStore = SELECTEDVALUE('Table'[Default Store])
RETURN
SWITCH(
TRUE(),
NOT(ISBLANK(EntranceStore)) && EntranceStore <> DefaultStore, EntranceStore,
NOT(ISBLANK(ExitStore))) && ExitStore <> DefaultStore, ExitStore,
NOT(ISBlank(EntranceStore)) || EntranceStore = DefaultStore || ISBLANK(ExitStore) || ExitStore = DefaultStore, DefaultStore,
DefaultStore
)