Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago

Dax Query

HI Team,

 

I need support. I have two dax queries one is A other is B. I need another dax query C in which logic should be like i have one column named as remark. So query should be like C =if(remark == AA give me A, remark == BB, B). But i am unable to use If condition with a column in dax query. Is there any other way, i tried switch true as well but after using it i am giving selected value as well due to which i need to select AA or BB or both in the slicer. If i am selecting both then only numbers are showing correct. Can anyone help me in this, it's urgent. Thanks in advance.

 

My query - 

GM% = SWITCH(TRUE(),SELECTEDVALUE('T1'[Remark])="AA",[AT%],SELECTEDVALUE('T1'[Remark])="AB",[AB%])

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  Anonymous ,

    I created some data:

     

    Here are the steps you can follow:

    1. Create calculated table.

    Table 2 =
    DISTINCT('Table'[Remake])

    2. Create measure.

    Test =
    var _select=SELECTCOLUMNS('Table 2',"select",[Remake])
    var _count=COUNTX(ALLSELECTED('Table 2'),[Remake])
    return
    SWITCH(
        TRUE(),
        "AA" in _select && _count =1,[MeasureA],
        "BB" in _select && _count =1,[MeasureB],
        "AA" in _select && "BB" in _select && _count=2,1
    )

    3. Result:

    Select“AA”:

    Select”BB”:

    Select“AA”&&”BB”:

     

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Bro, Thanks for your time. I tried your approach but it's giving me the same number for all the countries even after establishing the relationship as well between the tables. I did some changes in the query and cross checking the numbers let's see if that would be correct then i'll post it here as well. But thanks for your effort and time. Really appreciating.