Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
I have a measure in my Power BI report which stands as follows:
Solved! Go to Solution.
// This works on condition that Date_List is
// a Date table marked as such in the model.
Active Employees =
CALCULATE(
SUM( Employee[EmpValue] ),
KEEPFILTERS( Employee[Description] = "active" )
LASTDATE( Date_List[Date] )
) + 0
// If you don't have dates but only months,
// then you should store something like
// MonthID in your Date_List table and this
// field should be hidden and also monotonically
// increasing. Then you can write:
Active Employees =
CALCULATE(
SUM( Employee[EmpValue] ),
KEEPFILTERS( Employee[Description] = "active" )
TREATAS(
{MAX( Date_List[MonthID] )},
Date_List[MonthID]
),
ALL( Date_List )
) + 0
Best
D
// This works on condition that Date_List is
// a Date table marked as such in the model.
Active Employees =
CALCULATE(
SUM( Employee[EmpValue] ),
KEEPFILTERS( Employee[Description] = "active" )
LASTDATE( Date_List[Date] )
) + 0
// If you don't have dates but only months,
// then you should store something like
// MonthID in your Date_List table and this
// field should be hidden and also monotonically
// increasing. Then you can write:
Active Employees =
CALCULATE(
SUM( Employee[EmpValue] ),
KEEPFILTERS( Employee[Description] = "active" )
TREATAS(
{MAX( Date_List[MonthID] )},
Date_List[MonthID]
),
ALL( Date_List )
) + 0
Best
D
Thanks. Exactly what I was looking for!
As suggested by @lbendlin use a function that ignores filter context and I think you could improve your formula a bit and modify it to this, but this is my assumption that it might work for you.
Active Employees =
VAR OnlyActiveEmployees =
FILTER (
ALLSELECTED ( Employee[Description] ),
Employee[Description] = "Active"
)
VAR ActiveTotal =
CALCULATE ( SUM ( Employee[EmpValue] ), OnlyActiveEmployees )
RETURN
IF ( DISTINCTCOUNT ( Date_List[MmmYYYY] ) > 1, "NA", ActiveTotal + 0 )
I still get an "NA" as per your solution when the user selects more than 1 month.
I guess the issue is with this part of your formula:
IF ( DISTINCTCOUNT ( Date_List[MmmYYYY] ) > 1, "NA", ActiveTotal + 0 )
Thanks for your reply. Unfortunately I can't share the pbix file as it is a corporate document.
Basically, I would like to modify the existing measure (remove that "NA" part) so that when the user is selecting more than one date on the slicer (say, user selects June 2019, July 2019 and August 2019), the measure will output the value for August 2019 (which is the highest date among the 3 dates being selected.). So, if the user selects 2 dates (or more), the measure will output the value of the highest of these 2 dates (or more).
Are you sure you want to do that? Makes for a bad user experience.
I understand your point. The thing here is that Active employees refer to the number of active employees at a particular point in time and cannot be cummulative. That Date slicer controls other metrics on the Report and these metrics need cummulative figures (where the user is selecting more than 1 month on the Date slicer).
Hi @Anonymous ,
See if this video helps to get a snapshot of your active employees for a selected time period.
https://www.youtube.com/watch?v=rsx43g7TBBs
Regards,
Harsh Nathani
Appreciate with a Kudos!! (Click the Thumbs Up Button)
Did I answer your question? Mark my post as a solution!
Your first variable does not break out of the filter context. It will always only return one row. Use ALL or ALLSELECTED.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
19 | |
14 | |
13 | |
11 | |
8 |