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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

First date based on value

Hey,

 

I think this should be an easy one. Work with R&D data.

 

I am trying to flag the first date in which a product moved through stages of development.

 

The data contains dates, product codes and stages. Looks like this:

 

DateProduct codeStage
21-11-19Test1A
21-11-19Test2A
21-11-19Test3A
21-11-19Test4A
22-11-19Test1A
22-11-19Test2B
22-11-19Test3A
22-11-19Test4A
23-11-19Test1A
23-11-19Test2B
23-11-19Test3B
23-11-19Test4A

 

And I would like a column that returned this:

 

DateProduct codeStageFirst date on stage B
21-11-19Test1Anull
21-11-19Test2Anull
21-11-19Test3Anull
21-11-19Test4Anull
22-11-19Test1Anull
22-11-19Test2B22-11-19
22-11-19Test3Anull
22-11-19Test4Anull
23-11-19Test1Anull
23-11-19Test2C22-11-19
23-11-19Test3B23-11-19
23-11-19Test4Anull

 

I guess it has to involve firstdate function in DAX, but nothing I've tried so far has worked at all.

 

Any help would be appreciated.

 

Thanks!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Anonymous 

You would need to add some conditions if you want get the First Change of the Stage (to Stage B): 

 

Result =
VAR previousstage =
    CALCULATE (
        MIN ( 'Table'[Stage] ),
        ALLEXCEPT ( 'Table', 'Table'[Product code] ),
        'Table'[Date] < EARLIER ( 'Table'[Date] )
    )
VAR FirstChangeToB =
    CALCULATE (
        MIN ( 'Table'[Date] ),
        FILTER ( 'Table', 'Table'[Stage] = "B" ),
        FILTER ( 'Table', 'Table'[Product code] = EARLIER ( 'Table'[Product code] ) )
    )
RETURN
    IF (
        NOT ISBLANK ( previousstage )
            && previousstage <> 'Table'[Stage],
        FirstChangeToB,
        BLANK ()
    )

 

 change states dates.JPG


Best,
Paul

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

@Anonymous 

You would need to add some conditions if you want get the First Change of the Stage (to Stage B): 

 

Result =
VAR previousstage =
    CALCULATE (
        MIN ( 'Table'[Stage] ),
        ALLEXCEPT ( 'Table', 'Table'[Product code] ),
        'Table'[Date] < EARLIER ( 'Table'[Date] )
    )
VAR FirstChangeToB =
    CALCULATE (
        MIN ( 'Table'[Date] ),
        FILTER ( 'Table', 'Table'[Stage] = "B" ),
        FILTER ( 'Table', 'Table'[Product code] = EARLIER ( 'Table'[Product code] ) )
    )
RETURN
    IF (
        NOT ISBLANK ( previousstage )
            && previousstage <> 'Table'[Stage],
        FirstChangeToB,
        BLANK ()
    )

 

 change states dates.JPG


Best,
Paul

hnguy71
Super User
Super User

Hi @Anonymous ,
Here's a quick and dirty version to get you started. I think there's a better way of accomplishing this but I haven't had my coffee this morning yet. As a calculated column:

Date of Change = 
var _FirstDate = CALCULATE(MIN([Date]), FILTER(RnD, [Stage] < EARLIER([Stage]) && [Product code] = EARLIER([Product code])))
var _SecondDate = CALCULATE(MIN([Date]), FILTER(RnD, [Stage] = EARLIER([Stage]) && [Product code] = EARLIER([Product code])))
RETURN
IF(NOT ISBLANK(_FirstDate) && _SecondDate = [Date], [Date], BLANK())

 



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Helpful resources

Announcements
FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.