Forum Discussion
need help on how to implement case statement in DAX
Hi All
Need help on how to write DAX for the below scenario
i need to create a dax calcultions for calculated columns for below
1.case when Acc Number ='54112' then Amount
2.case whenAcc Number in ('54112','56019','44291','442901') then Amount.
Regards,
Anita
4 Replies
- miTutorials
Super User
You can use a Switch statement to achieve this.
When to use Switch Statement instead of IF Statement in PowerBI | MiTutorials - YouTube
- AnonymousNot applicable
Hi,
could you please let me know the dax logic how to write it.
Regards,
Anita
- miTutorials
Super User
Please see the video below.
When to use Switch Statement instead of IF Statement in PowerBI | MiTutorials - YouTube
- JTBusinessIntel
Helper I
Good Morning, Anita,
You should be able to do this with a Switch(True()) function.For a calulated column, your code should look something like this. :
Calculated Column = SWITCH( TRUE(), TableName[Acc Number] = "54112", TableName[Amount], TableName[Acc Number] in {"54112", "56019", "44291", "442901"}, TableName[Amount], Blank())The syntax for a measure changes some, so be aware of that. I used TableName as a placeholder for whatever your table is called in your model.
I wasn't sure what your return value was for anything outside the parameters so I put a blank() to make it easy.
Hopefully this helps!
Thanks,JTB