Forum Discussion

sjoshi's avatar
sjoshi
Helper II
7 years ago

IF, FILTER SUM Function

Hello,

 

I'm trying to do one simple thing but not sure why filter is not working

 

If accountnum ="14850" the take sum of amount for accountnum "52500" else null. This statement I have tried to write in below way and its giving incorrect sum value. What am I doing incorrect 

 

52500 = IF('LedgerTrans Fact'[AccountNum]="14850",
CALCULATE (
SUM ( 'LedgerTrans Fact'[AmountMST] ),
FILTER ( 'LedgerTrans Fact', 'LedgerTrans Fact'[AccountNum] = "52500" )
),0)

 

Thanks

Smita

19 Replies

  • Hi,

     

    Try this measure

     

    52500 = IF(HASONEVALUE('LedgerTrans Fact'[AccountNum]),IF(VALUES('LedgerTrans Fact'[AccountNum])="14850",CALCULATE(SUM('LedgerTrans Fact'[AmountMST]),'LedgerTrans Fact'[AccountNum]="52500"),0),BLANK())

     

    Hope this helps.

    • sjoshi's avatar
      sjoshi
      Helper II

       Hi Ashish

       

      I have tried to create measure in above way but ots returing always 0 value. Also I have created column with Greg's solution which is by adding all but both did not work and in values are 0 for 52500 column

       

      Thanks

      Smita

       

       

  • It's always going to return 0 because you are stating where account num = 14850 then sum where account number = 52500. You can't be both 14850 and 52500 at the same time.
    • sjoshi's avatar
      sjoshi
      Helper II

      Hello

      Yes I have modified the mesure and column to get the account number from the dimension table as below but still the values is zero. 

       

      52500 = IF(HASONEVALUE('LedgerTable Dim'[Accountnum]),IF(VALUES('LedgerTable Dim'[Accountnum])="14850",CALCULATE(SUM('LedgerTrans Fact'[AmountMST]),'LedgerTable Dim'[Accountnum]="52500"),0),BLANK())

       


      52500Col = IF(RELATED('LedgerTable Dim'[Accountnum])="14850",CALCULATE (
      SUM ( 'LedgerTrans Fact'[AmountMST] ),
      FILTER (ALL( 'LedgerTrans Fact'), RELATED('LedgerTable Dim'[Accountnum]) = "52500" )
      ),0)

       

       

       

       

      Thanks

      Smita