Forum Discussion
Not Able to apply condition while performing a calculation
- Anonymous2 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!
Hello v-jingzhan-msft,
Thanks for the reply.
I referred the link you provided, And I have similar condition to apply But here in case I have to pass 2 columns which are (harvests[facility_id] && harvests[harvest_id]) which contains dynamic values in place of [(Topic] ="A" && [type]="AC")
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!