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
Alyona_BI
Helper II
Helper II

How to define the value for each row in group based on another fields?

Hi guys!

 

I have this table with data: 

ItemNameStateDate
ATedNew01.08.2020
AKateNew02.08.2020
AKateActive04.08.2020
AAnnActive03.08.2020
AAnnClosed05.08.2020
BKateNew07.08.2020
BKateActive12.08.2020
BAdrewActive13.08.2020
BPeterActive14.08.2020
BKateClosed15.08.2020
CTedNew05.08.2020
CTedActive15.08.2020
CAndrewActive06.08.2020
CAnnActive08.08.2020
CAnnClosed16.08.2020

For each row within Item group i need to define Name as the one with "Active" State and minimum Date (for this Item). 

So the desired result should be: 

ItemNameStateDate First Name with Active State for Item
ATedNew01.08.2020 Ann
AKateNew02.08.2020 Ann
AKateActive04.08.2020 Ann
AAnnActive03.08.2020 Ann
AAnnClosed05.08.2020 Ann
BKateNew07.08.2020 Kate
BKateActive12.08.2020 Kate
BAdrewActive13.08.2020 Kate
BPeterActive14.08.2020 Kate
BKateClosed15.08.2020 Kate
CTedNew05.08.2020 Andrew
CTedActive15.08.2020 Andrew
CAndrewActive06.08.2020 Andrew
CAnnActive08.08.2020 Andrew
CAnnClosed16.08.2020 Andrew

 

Could anyone help me to do this with help of DAX and calculated column? 

 

Thanks in advance! 

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@Alyona_BI - See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __Previous = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Value])
RETURN
  __Current - __Previous

 

In your case, maybe:

First Name =
  VAR __Table = FILTER('Table',[Item]=EARLIER([Item]) && [State]="Active")
  VAR __MinDate = MINX(__Table,[Date])
RETURN
  MAXX(FILTER(__Table,[Date]=__MinDate),[Name])


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...

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

@Alyona_BI - See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __Previous = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Value])
RETURN
  __Current - __Previous

 

In your case, maybe:

First Name =
  VAR __Table = FILTER('Table',[Item]=EARLIER([Item]) && [State]="Active")
  VAR __MinDate = MINX(__Table,[Date])
RETURN
  MAXX(FILTER(__Table,[Date]=__MinDate),[Name])


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...

@Greg_Deckler you are really super user! 🙂

It works! Many thanks! 

@Alyona_BI - Glad to help! 🙂



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...

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.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.