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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
sunil222
Helper II
Helper II

calcualte head count of employee using dax calculation

table has employee name,doj,lwd columns , calculate head count of employees when employee terminates particular month , before months shows 1 value , after termination shows 0 value  and termination month also shows 0 value  in power bi dax     , date table is also there 

 

requirement as below please help me on this ,    employee terminates on feb2 , before months shows 1 , feb month also 1 , next months onwards shows 0 

 

empname           doj                lwd                           dec 23      jan 24   feb 24   mar 24  apr 24  may  24

raju              18-03-2020         02-02-2024                  1                1          1            0           0          0

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @sunil222 ,

Please follow these steps:

1.Using a dax expression, create a date table.

True =

CALENDAR(

    DATE(2023,11,1),

    DATE(2024,4,1))

2.Use a dax expression to create a calculated column for the year and month for the date table.

Month_year =

FORMAT('True'[Date],"mmm") &" "&RIGHT(YEAR('True'[Date]),2)

vkaiyuemsft_0-1707213494568.png

3.Create a measure to determine whether the date in the date table is less than the date of departure in the current table and assign a value to it.

Measure =

var _select=

SELECTCOLUMNS(

    FILTER(ALL('True'),

    'True'[Date]<=MAX('Table'[LWD])),"test",'True'[Month_year])

return

IF(

    MAX('True'[Month_year]) in _select,1,0)

4.At this time to create a matrix and in accordance with the following chart into the rows, columns, value fields, you will find that the date of the arrangement of the order is wrong, that is because the power bi default use of alphabetical sorting at this time.

vkaiyuemsft_1-1707213609779.png

vkaiyuemsft_2-1707213618326.png

5.Use the dax expression to create a calculation table again for sorting dates.

True 2 =

SUMMARIZE(

    'True','True'[Month_year],"min",MINX(FILTER(ALL('True'),'True'[Month_year]=EARLIER('True'[Month_year])),[Date]))

6.Select the Month_year column in the calculation table you just created and modify its sorting sequence.

vkaiyuemsft_3-1707213644135.png

7.Create a relationship for the two tables.

vkaiyuemsft_4-1707213644136.png

8.Change the column field in the matrix to the Month_year column in True 2. The final result is shown below.

vkaiyuemsft_5-1707213710055.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @sunil222 ,

Please follow these steps:

1.Using a dax expression, create a date table.

True =

CALENDAR(

    DATE(2023,11,1),

    DATE(2024,4,1))

2.Use a dax expression to create a calculated column for the year and month for the date table.

Month_year =

FORMAT('True'[Date],"mmm") &" "&RIGHT(YEAR('True'[Date]),2)

vkaiyuemsft_0-1707213494568.png

3.Create a measure to determine whether the date in the date table is less than the date of departure in the current table and assign a value to it.

Measure =

var _select=

SELECTCOLUMNS(

    FILTER(ALL('True'),

    'True'[Date]<=MAX('Table'[LWD])),"test",'True'[Month_year])

return

IF(

    MAX('True'[Month_year]) in _select,1,0)

4.At this time to create a matrix and in accordance with the following chart into the rows, columns, value fields, you will find that the date of the arrangement of the order is wrong, that is because the power bi default use of alphabetical sorting at this time.

vkaiyuemsft_1-1707213609779.png

vkaiyuemsft_2-1707213618326.png

5.Use the dax expression to create a calculation table again for sorting dates.

True 2 =

SUMMARIZE(

    'True','True'[Month_year],"min",MINX(FILTER(ALL('True'),'True'[Month_year]=EARLIER('True'[Month_year])),[Date]))

6.Select the Month_year column in the calculation table you just created and modify its sorting sequence.

vkaiyuemsft_3-1707213644135.png

7.Create a relationship for the two tables.

vkaiyuemsft_4-1707213644136.png

8.Change the column field in the matrix to the Month_year column in True 2. The final result is shown below.

vkaiyuemsft_5-1707213710055.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

sunil222
Helper II
Helper II

Please help me on this

Greg_Deckler
Community Champion
Community Champion

@sunil222 Not sure I am completely following this but perhaps:

Measure =
  VAR __lwd = MAX('Table'[lwd])
  VAR __Date = MAX('Dates'[Date])
  VAR __Result = 
    SWITCH(TRUE(),
      __Date <= __lwd, 1,
      YEAR(__Date) = YEAR(__lwd) && MONTH(__Date) = MONTH(__lwd), 1,
      0
    )
RETURN
  __Result

Otherwise, Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

sample data 

 

EMP_NameDesignationDOJLWD
Ruby PatelDelivery manager6/20/20211/15/2024

output:

 

Ruby patel has lwd so termination month and next month shows 0 before months shows values as 1

 

EMP_NameDesignationDOJLWDjan 24Feb 24
   1/15/202410

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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