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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
cpendley
Regular Visitor

How to calculate "Between or AND" in a nested if statement

I have been working on a calculated "start of month" count and "end of month" count to calculate average headcount.  what I am trying to do is:  IF AND[EE_List(adjhiredate)<STARTOFMONTH +1], AND[EE_List(termdate)>STARTOFMONTH]1, 0.

 

I've also tried it with my [Calendar(StartMonthDay)] but still can't get both variables to work.  I'll need to do the same for my "end of month" count.  

 

Current Try....

Active1stDayofMonth =
SWITCH(
TRUE(),
EE_List[AdjHireDate]<'Calendar'[StartDayMonth]+1
&& EE_List[TermDate]>'Calendar'[StartDayMonth],
1,
0)

 

Please help, I've tried &&, and, AND, if, IF.  Other formula's tried:

1. EmpCount = CALCULATE(COUNT([EmplID]), FILTER(ALL('Calendar'[FiscalYearMonthNumber]), 'Calendar'[FiscalYearMonthNumber] = MAX('Calendar'[FiscalYearMonthNumber])))

 

2. Active1stDayofMonth =
SWITCH(
TRUE(),
EE_List[AdjHireDate]<'Calendar'[StartDayMonth]+1
&& EE_List[TermDate]>'Calendar'[StartDayMonth],
1,
0)

 

AverageHeadcount = ([Start of Month]+[End of Month])/2

 

End of Month = CALCULATE (
COUNT ( 'EE_List'[EmplID]),
FILTER (
ALL ( 'EE_List' ),
COUNTROWS (
FILTER (
'EE_List',
NOT ISBLANK ( [TermDate] )
&& MONTH ( EARLIER( ( EE_List[AdjHireDate] ) )
= MONTH ( MAX ( 'Calendar'[EndofMonth] )
)
)))))

 

 

Start of Month =
CALCULATE (
COUNT ( EE_List[EmplID] ),
FILTER (
ALL ( EE_List),
COUNTROWS (
FILTER (
'EE_List',
NOT ISBLANK ( [TermDate] )
&& MONTH ( EARLIER ( 'EE_List'[AdjHireDate]) ) = MONTH ( MAX ('Calendar'[StartofMonth])
)
)
)
))

 

3. EmpCount2 =
VAR EarliestDate = CALCULATE(MIN('Calendar'[Date]),ALLSELECTED())
RETURN CALCULATE(DISTINCTCOUNT('EE_List'[Active_Inactive]),FILTER(ALL('Calendar'[Date]),'Calendar'[Date] <= MAX('Calendar'[Date]) && 'Calendar'[Date] >= EarliestDate))

 

4. Count of Active Employee =
VAR currentDate =
MAX ( 'Calendar'[Date])
RETURN
CALCULATE (
COUNTROWS ( EE_List ),
FILTER (
EE_List,
( EE_List[AdjHireDate] <= currentDate
&& EE_List[TermDate] >= currentDate )
&& EE_List[Active_Inactive] = 1
)
)

1 REPLY 1
Ashish_Mathur
Super User
Super User

Hi,

 

Share some data and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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