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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
alya1
Helper V
Helper V

historical data table - find date and type when customer upgrade happened?

Hello,

I have a historical customer table like below from date the customer joined till now:

Customer ID  Customer Type   Date
111 Basic1/1/2020
111Basic1/2/2020
111Main1/3/2020
222Advanced1/1/2020
222Pro1/2/2020
222Pro1/3/2020
333Basic1/3/2020

with many more customer ID's, rows, and other columns.


Is there a way to extract when (which date) and to what (which type) the Customer Type changed last (either from one type to another or from nothing to an exisiting type if they are new)?

Customer ID  Cutomer Type  Date
111Main1/3/2020
222Pro1/2/2020
333Basic1/3/2020


Not sure if it would be better to make the new data as a column because the next step would be to get the datediff between last type changed date to todays date. 

 

Thank you!

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @alya1 ,

 

I added some data.

vkaiyuemsft_0-1717665692320.png

 

Create the calculation table.

Table2 = 
VAR _currentId =
    MAX ( 'Table'[Customer ID  ] )
VAR _currentDate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Customer ID  ] = _currentId )
    )
RETURN
    SELECTCOLUMNS (
        FILTER (
            ADDCOLUMNS (
                SUMMARIZE (
                    'Table',
                    'Table'[Customer ID  ],
                    'Table'[Customer Type   ],
                    'Table'[Date]
                ),
                "Maxdate",
                    CALCULATE (
                        MAX ( 'Table'[Date] ),
                        FILTER (
                            ALLSELECTED ( 'Table' ),
                            'Table'[Customer ID  ] = EARLIER ( 'Table'[Customer ID  ] )
                        )
                    ),
                "Outcome",
                    CALCULATE (
                        MIN ( 'Table'[Date] ),
                        FILTER (
                            ALLSELECTED ( 'Table' ),
                            'Table'[Customer ID  ] = EARLIER ( 'Table'[Customer ID  ] )
                                && 'Table'[Customer Type   ] = EARLIER ( 'Table'[Customer Type   ] )
                        )
                    )
            ),
            [Date] = [Maxdate]
        ),
        [Customer ID  ],
        [Customer Type   ],
        [Outcome]
    )

vkaiyuemsft_1-1717665738541.png

 

Best Regards,

Clara Gong

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

12 REPLIES 12
Anonymous
Not applicable

Hi @alya1 ,

 

Thanks for the reply from @sevenhills , please allow me to provide another insight: 

 

1. Create a calculated column to sort the Customer Type.

 

Column =
SWITCH(TRUE(),
'Table'[Customer Type ] = "Basic",1,
'Table'[Customer Type ] = "Main",2,
'Table'[Customer Type ] = "Advanced",3,
'Table'[Customer Type ] = "Pro",4)

 

 

2. Create the calculation table.

 

LastCustomerTypeChange = 
SUMMARIZE(
    FILTER(
        'Table',
        'Table'[Column] = CALCULATE(MAX('Table'[Column]), ALLEXCEPT('Table', 'Table'[Customer ID  ]))
    ),
    'Table'[Customer ID  ],
    "CustomerType", LASTNONBLANK('Table'[Customer Type   ], MAX('Table'[Date])),
    "LastChangeDate", MIN('Table'[Date]),
    "DateDiffToady",DATEDIFF(MIN('Table'[Date]),TODAY(),DAY)
)

 

vkaiyuemsft_0-1717123241963.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

Hello Clara, thank you for your reply! Sadly, the customer type is extensive with many more categories then example. Sometimes customers go from higher level (like Pro) back to lower level (like Basic). Is there a way to show the latest Customer Type by date instead of MAX? 

Anonymous
Not applicable

Hi @alya1 ,

 

I added some data.

vkaiyuemsft_0-1717665692320.png

 

Create the calculation table.

Table2 = 
VAR _currentId =
    MAX ( 'Table'[Customer ID  ] )
VAR _currentDate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Customer ID  ] = _currentId )
    )
RETURN
    SELECTCOLUMNS (
        FILTER (
            ADDCOLUMNS (
                SUMMARIZE (
                    'Table',
                    'Table'[Customer ID  ],
                    'Table'[Customer Type   ],
                    'Table'[Date]
                ),
                "Maxdate",
                    CALCULATE (
                        MAX ( 'Table'[Date] ),
                        FILTER (
                            ALLSELECTED ( 'Table' ),
                            'Table'[Customer ID  ] = EARLIER ( 'Table'[Customer ID  ] )
                        )
                    ),
                "Outcome",
                    CALCULATE (
                        MIN ( 'Table'[Date] ),
                        FILTER (
                            ALLSELECTED ( 'Table' ),
                            'Table'[Customer ID  ] = EARLIER ( 'Table'[Customer ID  ] )
                                && 'Table'[Customer Type   ] = EARLIER ( 'Table'[Customer Type   ] )
                        )
                    )
            ),
            [Date] = [Maxdate]
        ),
        [Customer ID  ],
        [Customer Type   ],
        [Outcome]
    )

vkaiyuemsft_1-1717665738541.png

 

Best Regards,

Clara Gong

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

 

Hi Clara, This is amazing! I learned a lot from your reply 😄 Thank you so much

sevenhills
Super User
Super User

If it is DAX table, you are looking for, do these:

 

Go the modeling tab, click "New Table" and do this DAX:

 

Summary table = 
FILTER (
    'Table',
    'Table'[Date]
        = CALCULATE (
            MAX ( 'Table'[Date] ),
            ALLEXCEPT ( 'Table', 'Table'[Customer ID  ] )
        )
)

 

and format the date column per your needs

 

IP:

sevenhills_1-1717106157443.png

 

OP:

sevenhills_0-1717106139352.png

 

 

 

It was not clear whether you want to add new column or measure to calculate the date.

 

Add this measure to your summary table:

 

Diff Date Today = DATEDIFF(max('Table'[Date]),TODAY(),DAY)

 

sevenhills_3-1717106564201.png

 

 

Calculated column: very less likely you need today date diff as column, but giving that syntax:

 

Summary table 2 = ADDCOLUMNS(
FILTER (
    'Table',
    'Table'[Date]
        = CALCULATE (
            MAX ( 'Table'[Date] ),
            ALLEXCEPT ( 'Table', 'Table'[Customer ID  ] )
        )
), "Diff Today", DATEDIFF('Table'[Date], TODAY(), DAY)
)

 

sevenhills_2-1717106537606.png

 

Hello, thank you for your reply. Please note I would like "the date the customers type changed last". So for ID 222, is it possible to pull 1/2/2020?

what is overall output you need?

Yes, we can get the second largest one!

Thank you! Is there a way to extract when (which date) and to what (which type) the Customer Type changed last (either from one type to another or from nothing to an exisiting type if they are new)? A new table format is good. 

You need to provide the data sample of your output, as it is not clear what you are expecting In the output. 

It is the second table in the original question: 

"Is there a way to extract when (which date) and to what (which type) the Customer Type changed last (either from one type to another or from nothing to an exisiting type if they are new)?

Customer ID  Cutomer Type  Date
111Main1/3/2020
222Pro1/2/2020
333Basic1/3/2020

Based on @Anonymous solution, Now, I understand what you are looking for!

 

I saw you already accepted the solution! Great!

 

Based on Clara answer, I did this, as I was not sure what you are looking!

 

Now that I know what you are looking for, I am providing the same in another DAX

 

Summary table 3 = 
var _r = FILTER (
            ADDCOLUMNS( 
                SUMMARIZE('Table', 'Table'[Customer ID  ], 'Table'[Customer Type   ], 'Table'[Date])
                , "Min Date by CT"
                , CALCULATE(MIN('Table'[Date]), FILTER('Table', 'Table'[Customer ID  ] = EARLIER('Table'[Customer ID  ] ) && 'Table'[Customer Type   ] = EARLIER('Table'[Customer Type   ]) ))

                , "Max Date by C"
                , CALCULATE( MAX('Table'[Date]), FILTER('Table',  'Table'[Customer ID  ] = EARLIER('Table'[Customer ID  ] )))

                , "Count Rows", COUNTROWS('Table')

            ) , 'Table'[Date] = [Max Date by C] )

var _r2 =
        SELECTCOLUMNS(
            ADDCOLUMNS( _r
                 , "Date Diff Today"
                 ,  DATEDIFF([Min Date by CT],TODAY(),DAY) -- I prefere this as measure
            )
        , "Customer ID", [Customer ID  ]
        , "Customer Type", [Customer Type   ]
        , "Date", [Min Date by CT]
        , "Days as of Today", [Date Diff Today] 
        ) 

RETURN _r2

 

Output:

sevenhills_1-1717705940674.png

 

I added few extra columns to help in debugging like count rows!

 

Thank you

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors