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
TiffanyT_IL
Frequent Visitor

Change in Category - First Category and date and all following dates when category changes

Greetings!
I am looking for a solution to display the first date and first category and then all subsequent changes in a category and its associated date. I found an earlier post that helped immensely, but I have been unable to modify it to solve my specific problem. Thoughts?

Here is a moc data set:

ID         Date                Category

A1006/10/2021RN
A1006/11/2021RN
A1006/12/2021RN
A1006/18/2021RN
A1006/19/2021LPN
A1006/19/2021LPN to RN ADJ
A1006/21/2021LPN
A1006/21/2021LPN to RN ADJ
A1006/22/2021LPN
A1006/22/2021LPN to RN ADJ
A1006/22/2021LPN to RN ADJ
A1007/3/2021RN
A1007/5/2021RN
A1007/6/2021RN
A1007/7/2021RN

 

Desired Report

IDDate of ChangeCategory
A1006/10/2021RN
 6/19/2021LPN
 6/19/2021LPN to RN ADJ
 6/21/2021LPN
 6/21/2021LPN to RN ADJ
 6/22/2021LPN
 6/22/2021LPN to RN ADJ
 7/3/2021RN


Calculated Column Category Change Date =

VAR _Status = 'Table1'[Category]

VAR _Date = Table1[Date]

VAR _FIRSTClassDt =

CALCULATE (

MIN ( Table1[Date] ),

ALLEXCEPT ( Table1, Table1[ID] ),

Table1[Category] <> _Status,

Table1[Date] > _Date

)

RETURN _FIRSTClassDt

 

Calculated Column Category Change =

VAR _LastChangeDate = Table1[Category Change Date]

VAR _Class = Table1[Category]

RETURN

CALCULATE(

MIN (Table1[Category] ),

ALLEXCEPT (Table1,Table1[ID]),

Table1[Category] <> _Class

)
Which returned this:

TiffanyT_IL_0-1663091580348.png

If possible, I would prefer to have a measure to do this.

Any help would be greatly appreciated!

 

 

1 ACCEPTED SOLUTION
v-rongtiep-msft
Community Support
Community Support

Hi @TiffanyT_IL ,

I have created a simple sample, please refer to it to see if it helps you.

Add an index column first.

Then create a measure.

Measure =
VAR _1 =
    CALCULATE (
        MAX ( 'Table'[category] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Index]
                = SELECTEDVALUE ( 'Table'[Index] ) - 1
        )
    )
RETURN
    IF ( MAX ( 'Table'[category] ) <> _1, MAX ( 'Table'[Date] ), BLANK () )

Or a column.

Column = 
VAR _1 =
    CALCULATE (
        MAX ( 'Table'[category] ),
        FILTER (
             ( 'Table' ),
            'Table'[Index]
                = EARLIER(  'Table'[Index] ) - 1
        )
    )
RETURN
    IF ( ( 'Table'[category] ) <> _1, ( 'Table'[Date] ), BLANK () )

 

Finally filter the measure or column is not blank.

vpollymsft_0-1663124354334.png

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
TiffanyT_IL
Frequent Visitor

This is great! Thank you so much.

My actual data was a bit more complex than the sample but with grouping, adding the index to the grouping and an extra condition in the filter to account for more IDs, it was perfect.

Thank you again!

v-rongtiep-msft
Community Support
Community Support

Hi @TiffanyT_IL ,

I have created a simple sample, please refer to it to see if it helps you.

Add an index column first.

Then create a measure.

Measure =
VAR _1 =
    CALCULATE (
        MAX ( 'Table'[category] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Index]
                = SELECTEDVALUE ( 'Table'[Index] ) - 1
        )
    )
RETURN
    IF ( MAX ( 'Table'[category] ) <> _1, MAX ( 'Table'[Date] ), BLANK () )

Or a column.

Column = 
VAR _1 =
    CALCULATE (
        MAX ( 'Table'[category] ),
        FILTER (
             ( 'Table' ),
            'Table'[Index]
                = EARLIER(  'Table'[Index] ) - 1
        )
    )
RETURN
    IF ( ( 'Table'[category] ) <> _1, ( 'Table'[Date] ), BLANK () )

 

Finally filter the measure or column is not blank.

vpollymsft_0-1663124354334.png

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.