Forum Discussion

Parth_1's avatar
Parth_1
Helper I
2 years ago
Solved

Not Able to apply condition while performing a calculation

Hello Guys, I am stuck at this, I am doing a project  where I have 5 columns(facility id, harvest id, last_ modified(date), plantCount, source) and based onthat I want to calculate total Active pla...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Parth_1 

     

    If you will add this calculation along with facility_id and harvest_id in the same visual, you can use a simpler measure like below to get the value of the latest modified date for each pair of facility_id and harvest_id. Columns in the same visual will pass these filters to the measure dynamically. 

    Latest Count = 
    var maxDate = MAX('Table'[last_ modified])
    return
    CALCULATE(SUM('Table'[plantCount]),'Table'[last_ modified]=maxDate, 'Table'[source]="Active")

     

    If you use slicers or filters to choose facility_id and harvest_id dynamically, above measure also works. However it will also be affected by other filters if any. 

     

    Or you can use 

    Latest Count 2 = 
    Var _maxdate=CALCULATE(MAX('Table'[last_ modified]),FILTER(ALL('Table'),[facility id]=SELECTEDVALUE('Table'[facility id])&&[harvest id]=SELECTEDVALUE('Table'[harvest id])))
    Return
    CALCULATE(MAX('Table'[plantCount]),FILTER(ALL('Table'),[last_ modified]=_maxdate&&[facility id]=SELECTEDVALUE('Table'[facility id])&&[harvest id]=SELECTEDVALUE('Table'[harvest id])))

    SELECTEDVALUE function will get the value for you dynamcially. 

     

    Best Regards,
    Jing
    If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!