Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

How to Use a variable as filter in caclulate

I am trying to sum all the employees that left between 30 to 365 days.
how can I use the "flag" in the calculate formula?
 
 
# Under 1 year =
var workStartDate=MAX('Employee data for PBI'[Work Start Date])
var workEndDate=MAX('Employee data for PBI'[Final Process Date])
var seniority= DATEDIFF(workStartDate, workEndDate, DAY)
var flag=IF(seniority>=30 && seniority<=365,1,0)
var emps=CALCULATE(SUM('Employee data for PBI'[# Terminated]))
return emps
2 REPLIES 2
Tanushree_Kapse
Impactful Individual
Impactful Individual

Hi @Anonymous ,
you can use this measure:

# Under 1 year =
var workStartDate=MAX('Employee data for PBI'[Work Start Date])
var workEndDate=MAX('Employee data for PBI'[Final Process Date])
var seniority= DATEDIFF(workStartDate, workEndDate, DAY)
var flag=IF(seniority>=30 && seniority<=365,1,0)
return CALCULATE(SUM('Employee data for PBI'[# Terminated]),seniority>=30 && seniority<=365)
 
 
Anonymous
Not applicable

thanks @Tanushree_Kapse  but when I try what you suggest I'm getting the following error :

 

The True/False expression does not specify a column. Each True/False expressions used as a table filter expression must refer to exactly one column.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.