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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Lucianovaz
Frequent Visitor

count employee and average age year for year and status criteria

Dear friends,
I need help in dax powerbi to get the number of active employees (Status="N") and the average age of employees per year.
Taking into account the update date (UpdateStatus) <= dCalendar[date] && Status="N".

Note: Only calculate if UpdateStatus = LastDate and Status = "N"


its not works

Holding stage age2 =
var _dtxx=MAX(Dates[Date])
var _dtx=MAX('Table'[UpdateStatus])
VAR startdate = MAXX(FILTER('Table', 'Table'[Status] = "N"), 'Table'[BirthDay])
RETURN
  DATEDIFF( startdate,_dtxx,YEAR)
-----------------------------------------------------
Média Idade3 =
var filtro1 = filter(all('Table'[Status]),'Table'[Status]="n")
var ultimadata = lastdate('Table'[UpdateStatus])
var _dtxx = MAX(Dates[Date])
var filtro2 = filter(all('Table'[UpdateStatus]),'Table'[UpdateStatus]=ultimadata && ultimadata<=_dtxx)
 
 


var result = calculate(
                distinctcount('Table'[Employee]),filtro1,filtro2)
               
               
return result


sample bd

EmployeeFirst NameGenderBirthDayUpdateStatusstatus
110BuddyF18/03/194320/01/1966N
114CarltonF24/02/199024/02/2001N
114CarltonF24/02/199024/02/2004S
114CarltonF24/02/199024/02/2008N
114CarltonF24/02/199024/02/2011S
115TheodoraM21/01/192125/02/1946N
116ErnestF02/10/198102/10/1999N
140KirstyM14/11/195706/09/2002N
140KirstyM14/11/195706/09/2012S
152AleezaM26/11/197026/11/2001N
160JasonM10/06/197410/06/2010N
166KianM28/04/198028/04/2012N
170GloriaF21/06/198922/07/2010N
170GloriaF21/06/198922/07/2016S
202AndreeaF13/03/199308/05/2013N
210SiannaM15/08/196805/05/1985N
211SaimaM07/02/199802/08/2000N
212AntonioF19/08/193726/02/1959N
213AbdullahM10/03/194227/06/1964N
216IsabellM20/01/196720/01/1999N
216IsabellM20/01/196720/01/2011S




Lucianovaz_0-1664997342484.png

 

3 REPLIES 3
Lucianovaz
Frequent Visitor

Dear friend,
With the power query I am restricted and I can only bring information to the present day.

I need to bring it temporally, that is, if I select a year in the data segmentation [year] and show me the amount and average age of those employees who have UpdateStatus =Lastdate(UpdateStatus) && Status ="N" as shown in example in the image.
I know it seems easy for many, but I couldn't solve it, please help me!!!

Lucianovaz_0-1665156378225.png

 

v-easonf-msft
Community Support
Community Support

Hi, @Lucianovaz 

It is recommended to preprocess the data in PQ and then use dax to calculate the result.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZNNT8MwDIb/S8+TaqdJ2hwHAgQILuM27ZCpkVaptFK7Hcavx06aLHCiSK1qq37y+iv7fYEIxaa4u7Ttlb6P9GJTQlWikRU5AkpAcrQm5704bJiQZN/bqT+Pw8IIWYKgMAPJEQD4D4bjdiuZZr0OYqajyP44ubEdJ0vmG8dhqFtwnFDhBJk3ge2HaXDzedHhEKCoBjPHmBsiOYHXbprP10UFZYmsompGdAmGyxGrERS3ahTb2965r1SLDkgNyfk5HM0/XuzsW+ZFaOqaCZkcEoGM0D4vGwFBOyO5dkjOktUCeO2nfpw6G8eCQaPhDglRQv1L46+ITrUL37rt0E7ORQarsM2GtxkoM8VMlWSEl9xRKUPsF9K4G9553iuKp4c0VYb45bHdZyQokbBiTRg94dRhyIiQGC1lN8bETFCp6jAVf4AyGcNJbo/tpe/tKRuMv5t8nqhDO7TMIO7G82yPru/jbOIVrjPHmLXM7c4cvgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Employee = _t, #"First Name" = _t, Gender = _t, BirthDay = _t, UpdateStatus = _t, status = _t]),
    #"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"BirthDay", type date}, {"UpdateStatus", type date}}, "en-GB"),
    #"Grouped Rows" = Table.Group(#"Changed Type with Locale", {"Employee", "First Name", "Gender", "BirthDay"}, {{"SubTable", each _, type table [Employee=nullable number, First Name=nullable text, Gender=nullable text, BirthDay=nullable text, UpdateStatus=nullable text, status=nullable text]}}),
    #"Aggregated SubTable" = Table.AggregateTableColumn(#"Grouped Rows", "SubTable", {{"UpdateStatus", List.Last, "Max UpdateStatus"}, {"status", List.Last, "Last status"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Aggregated SubTable",{{"Max UpdateStatus", type date}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type1", each ([Last status] = "N"))
in
    #"Filtered Rows"

 

Best Regards,
Community Support Team _ Eason

 

example: 114, not against current year as last status ="S" Correct.

Now, if I select the year 2008 it had to appear since the last status ="N" was 02/24/2008

teste dax.jpg
test acc.jpgteste3 dax.jpg

I created a measure [QTDE6] with addcolumns, the count worked, but I don't know if there is another cleaner way to count.

And another thing I need to calculate the age of these employees that were filtered and then do an average age. Please help me !!!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.