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
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
Super User
Super User

@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])

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

@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])

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler you are really super user! 🙂

It works! Many thanks! 

@Alyona_BI - Glad to help! 🙂


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.

Top Solution Authors