Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Python script to DAX

Hi, I am trying to convert the below python script to DAX Calculated column:           import numpy as np dataset["OBV"] = np.where(dataset['close'] > dataset['close'].shift(1), dataset['volum...
  • v-lili6-msft's avatar
    v-lili6-msft
    6 years ago

    hi Anonymous 

    for your requirement, you need to create two column to get your requirement:

    judgecolumn = var _yesterdaydate=CALCULATE(MAX('Table'[As of Date]),FILTER('Table','Table'[As of Date]<EARLIER('Table'[As of Date])))
    var _yesterdayclose=CALCULATE(SUM('Table'[Close]),FILTER('Table','Table'[As of Date] = _yesterdaydate))
    return
    
    DIVIDE('Table'[Close]-_yesterdayclose,ABS('Table'[Close]-_yesterdayclose)) *'Table'[Volume]
    OBV = 
    
    SUMX(FILTER('Table','Table'[As of Date]<=EARLIER('Table'[As of Date])),[judgecolumn])

     

    Result:

    For first date of your sample data, there is no yesterday OBV, so I have give a fixed value

    OBV = 
    
    SUMX(FILTER('Table','Table'[As of Date]<=EARLIER('Table'[As of Date])),[judgecolumn])+287025018164

     

    here is sample pbix file, please try it.

     

     

    Regards,

    Lin