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
Anonymous
Not applicable

DAX:- Count Last 5+ AB values from MAX DATE with some condtions

Hello All,

 

I have a data set as below table.

EmpID      Date              Daytype

12825621/10/2018WO
12825622/10/2018AB
12825623/10/2018AB
12825624/10/2018AB
12825625/10/2018NT
12825626/10/2018AB
12825627/10/2018WO
12825628/10/2018WO
12825629/10/2018AB
12825630/10/2018AB
1282561/11/2018WO
1282562/11/2018AB
1282563/11/2018NT
1282564/11/2018AB
1282565/11/2018AB
12825721/10/2018WO
12825722/10/2018AB
12825723/10/2018AB
12825724/10/2018AB
12825725/10/2018NT
12825726/10/2018AB
12825727/10/2018WO
12825728/10/2018WO
12825729/10/2018AB
12825730/10/2018AB
1282571/11/2018WO
1282572/11/2018HL
1282573/11/2018AB
1282574/11/2018AB
1282575/11/2018AB

 

From above table i am trying to calculate the values of AB from max date.

I.e until and unless NT value does'nt shows up, it should continue to count only AB values, even though if WO or HL values shows up in middle.
* It should print the value at only MAX date.

 

The expected output looks like this.

 

EmpID            Date        Daytype  ABCount

12825621/10/2018WO 
12825622/10/2018AB 
12825623/10/2018AB 
12825624/10/2018AB 
12825625/10/2018NT 
12825626/10/2018AB 
12825627/10/2018WO 
12825628/10/2018WO 
12825629/10/2018AB 
12825630/10/2018AB 
1282561/11/2018WO 
1282562/11/2018AB 
1282563/11/2018NT 
1282564/11/2018AB 
1282565/11/2018AB2
12825721/10/2018WO 
12825722/10/2018AB 
12825723/10/2018AB 
12825724/10/2018AB 
12825725/10/2018NT 
12825726/10/2018AB 
12825727/10/2018WO 
12825728/10/2018WO 
12825729/10/2018AB 
12825730/10/2018AB 
1282571/11/2018WO 
1282572/11/2018HL 
1282573/11/2018AB 
1282574/11/2018AB 
1282575/11/2018AB6

 

 

Can anyone please suggest me that how we can do this with DAX.

1 ACCEPTED SOLUTION
PattemManohar
Community Champion
Community Champion

@Anonymous Please try this as a "New Column"

 

Result = 
VAR _MaxDateAB = CALCULATE(MAX(Test67[Date]),FILTER(Test67,Test67[EmpID] = EARLIER(Test67[EmpID]) && Test67[DayType] = "AB" ))
VAR _MaxDateNT = CALCULATE(MAX(Test67[Date]),FILTER(Test67,Test67[EmpID] = EARLIER(Test67[EmpID]) && Test67[DayType] = "NT" ))
VAR _Count = CALCULATE(COUNTROWS(Test67),FILTER(Test67,Test67[DayType] = "AB" && Test67[Date] > _MaxDateNT && Test67[EmpID] = EARLIER(Test67[EmpID])))
VAR _CurrEmpID = Test67[EmpID]
RETURN IF(Test67[EmpID] = _CurrEmpID && Test67[Date] = _MaxDateAB,_Count,BLANK())

image.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




View solution in original post

3 REPLIES 3
PattemManohar
Community Champion
Community Champion

@Anonymous Please try this as a "New Column"

 

Result = 
VAR _MaxDateAB = CALCULATE(MAX(Test67[Date]),FILTER(Test67,Test67[EmpID] = EARLIER(Test67[EmpID]) && Test67[DayType] = "AB" ))
VAR _MaxDateNT = CALCULATE(MAX(Test67[Date]),FILTER(Test67,Test67[EmpID] = EARLIER(Test67[EmpID]) && Test67[DayType] = "NT" ))
VAR _Count = CALCULATE(COUNTROWS(Test67),FILTER(Test67,Test67[DayType] = "AB" && Test67[Date] > _MaxDateNT && Test67[EmpID] = EARLIER(Test67[EmpID])))
VAR _CurrEmpID = Test67[EmpID]
RETURN IF(Test67[EmpID] = _CurrEmpID && Test67[Date] = _MaxDateAB,_Count,BLANK())

image.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




Anonymous
Not applicable

Wow @PattemManohar... Thats was quick and awsome..

 

It worked like a charm.

 

thank you soo much...

Kudos...

@Anonymous Thank You !!




Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




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.