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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
SriBhaskar
Regular Visitor

Correct the DAX measure closing count DAX measure

I have two tables. Allresources and DateTable. 
Below is the datetable created in Power BI 

Date MonthNoMonth YeaYear
06-03-2024 00:00:003Mar 242024
07-03-2024 00:00:003Mar 242024
08-03-2024 00:00:003Mar 242024
09-03-2024 00:00:003Mar 242024
10-03-2024 00:00:003Mar 242024
11-03-2024 00.00.003Mar242024
12-03-2024 00:00:003Mar242024

'Allresources' Table 

DivisionOnboarding DateOffboarding End DateCorp ID
Governance01-01-202430-08-2024CHEPRASA
Governance15-01-202430-08-2024STAVANAN
SF01-01-202407-09-2024SUPV
MTE11-01-202408-12-2025REKAMBI
Governance01-01-202431-12-2025JAGAPATI
SF15-01-202431-12-2025PRRASAL
MCM21-02-202431-12-2026SWAROOM
MCM22-02-202405-12-2025**bleep**ALSU
SF22-01-202408-12-2025FEESINGH

Both have a active relation with Date column in DateTable and OffBOarding End Date column  in AllResources Table.
Inactive realtionship with Date   column in DateTable and OnBOarding Date column in AllResources Table.
I write the below code for getting the the monthwise and division wise closing head count.. How many employees are there at the end of that month.

DiviSeqMonthClosingCount =
VAR CurrentMonth = SELECTEDVALUE (DateTable [MonthNo])
VAR CurrentYear = SELECTEDVALUE (DateTable[Year])
VAR EOMonthNo = Day (EOMONTH (Date (CurrentYear, CurrentMonth,1),0))
Return CALCULATE (DISTINCTCOUNT (A11Resources [Corp ID]), AllResources [OnboardingDateTime] <= date (CurrentYear, CurrentMonth, EOMonthNo) && (
(A11Resources [Offboarding End Date] > date (CurrentYear, CurrentMonth, EOMonthNo)) || ISBLANK (A11Resources [Offboarding End
Date])), ALL (DateTable), USERELATIONSHIP (AllResources [OnboardingDateTime], DateTable[Date]))


I am getting the below output. Below the DiviMonthClosingcount needs to repeat the count for other months also like Opening Count measure. 

DivisionMonthYear Opening Count DiviMonthClosingcount 
GovernanceJan'251717
GovernanceFeb'2517 
GovernanceMar'2517 
Governance
5
Apr 2517 
GovernanceMay 2517 
MCMJan 256871
MCMFeb 2568 
MEM25-Mar6871
MCMApr"2568 
MCMMay 256870

I need the below output for closing count.

DivisionMonthYear Opening Count DiviMonthClosingcount 
GovernanceJan'251717
GovernanceFeb'251717
GovernanceMar'251717
Governance
5
Apr 251717
GovernanceMay 251717
MCMJan 256871
MCMFeb 256871
MEM25-Mar6871
MCMApr"256871
MCMMay 256870

I am unable to find out the missing logic as I tried with Filter function also and even I put the ALL(Allresources). I am not getting the desired result. Please help me out on this. I think some where I missed the filter or someting in the logic. The relationship between the tables also explained above.

Thanks

Dathy

 

1 ACCEPTED SOLUTION
sjoerdvn
Super User
Super User

I've tested this with the data and measure you provided. Apart from having to correct quite some column names in there it actually worked fine. It would only fail if the cross filter direction of the relationships with the date table are set to "Both". 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @SriBhaskar ,

 

Please try:

MEASURE = 
VAR max_date = MAX ( 'DateTable'[Date] )
RETURN
CALCULATE (
    COUNTROWS ( 'AllResources' ),
    'AllResources'[Onboarding Date] <= max_date,
    'AllResources'[Offboarding End Date] >= max_date 
        || ISBLANK ( 'AllResources'[Offboarding End Date] ),
    CROSSFILTER ( 'AllResources'[Offboarding End Date], 'DateTable'[Date], NONE )
)

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

sjoerdvn
Super User
Super User

I've tested this with the data and measure you provided. Apart from having to correct quite some column names in there it actually worked fine. It would only fail if the cross filter direction of the relationships with the date table are set to "Both". 

SriBhaskar
Regular Visitor

I already tried this approach but I am not getting the desired output as mentioned above. Any other approach you have please let me know

SriBhaskar
Regular Visitor

This I already tried.I am not getting the desired output.

bhanu_gautam
Super User
Super User

@SriBhaskar , Try using

 

DAX
DiviSeqMonthClosingCount =
VAR CurrentMonth = SELECTEDVALUE(DateTable[MonthNo])
VAR CurrentYear = SELECTEDVALUE(DateTable[Year])
VAR EOMonthDate = EOMONTH(DATE(CurrentYear, CurrentMonth, 1), 0)
RETURN
CALCULATE(
DISTINCTCOUNT(AllResources[Corp ID]),
FILTER(
AllResources,
AllResources[Onboarding Date] <= EOMonthDate &&
(AllResources[Offboarding End Date] > EOMonthDate || ISBLANK(AllResources[Offboarding End Date]))
),
ALL(DateTable),
USERELATIONSHIP(AllResources[Onboarding Date], DateTable[Date])
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.