Forum Discussion

ph's avatar
ph
Icon for Helper I rankHelper I
7 years ago
Solved

get value from table with 2 conditions

Hi all !   I have problem with unfriendly DAX :( I need to get this value (written in T-SQL):   select [Amount] from [Account Balance] where left(account,3)=211 and date=today()   so I wrote ...
  • Anonymous's avatar
    Anonymous
    7 years ago

    Mate, DAX is simple but not easy - let that sink in. I'll give you good advice: get yourself a good book on DAX and read. The best book by far is "The Ultimate Guide To DAX" by The Italians.

     

    Second, filters in CALCULATE are always tables. Even though you can write

     

    T[Col] = "value"

     

    it's always expanded into

     

    FILTER(

        ALL ( T[Col] ),

        T[Col] = "value"

    )

     

    It means, among others, that you can't use two different columns in such a boolean expression. And this is what you're trying to do.

     

    Secondly, don't do this: left(Account[Accounting Class]; 3). Please create a calculated column with this formula in it.

     

    Thirdly, then you'll be able to do this:

     

    Acc 211 =
    var __today = [Today formatted]
    var __acc211 =
    	CALCULATE(
    		SUM( 'Account Balance'[Amount] ),
    		'Date'[Date ID] = __today,
    		Account[Accounting Class 3] = "211" -- this is the new calculated column (hidden)
    	)
    return
    	__acc211

     

    Easy? That's what I thought :)

     

    Best

    Darek