Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

DAX calculation help

Hi   Need your help and suggestion on achieveing the below   I have sample data like below. ID Transaction Type Qty From Date Todate 1234 Opening Stock 50 3/11/2019...
  • v-lili6-msft's avatar
    v-lili6-msft
    7 years ago

    hi, Anonymous 

    If you could try this measure

    Spoiler
    Measure = var _frodate=CALCULATE(MIN('Date'[Date]))
    var _todate=CALCULATE(MAX('Date'[Date])) return
    IF(SELECTEDVALUE('Table'[Transaction Type])="Opening Stock",CALCULATE(SUM('Table'[Qty]),FILTER('Table','Table'[From Date]=_frodate)),
    IF(SELECTEDVALUE('Table'[Transaction Type])="Closing Stock",CALCULATE(SUM('Table'[Qty]),FILTER('Table','Table'[Todate]=_todate)),
    IF(SELECTEDVALUE('Table'[Transaction Type])="Received",CALCULATE(SUM('Table'[Qty]),FILTER('Table','Table'[From Date]>=_frodate&&'Table'[Todate]<=_todate)))))

    result:

    and here is pbix file, please try it.

     

    Best Regards,

    Lin