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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

count category changes per user

Hello
How can i count how many times the user changes category?
How to calculate the value of n changes?
ps the changes column doesn't exist in my table
thanks

 

idstart dateend datecategorychangesn changes
910011/07/201905/07/2019category 1  
910011/10/201911/10/2019category 2x1
910002/12/201929/11/2019category 2  
222202/11/198230/09/1990category 1x 
222201/10/199030/09/1993category 2x 
222201/10/199328/02/1994category 3x3
369801/03/200431/12/2005category 5  
369801/01/200631/12/9999category 5 0
1 ACCEPTED SOLUTION
v-luwang-msft
Community Support
Community Support

Hi @Anonymous ,

Pls use the below dax to create a new column:

n change1 =
VAR maxdate =
    CALCULATE ( MAX ( 'Table'[start date] ), ALLEXCEPT ( 'Table', 'Table'[id] ) )
RETURN
    IF (
        'Table'[start date] = maxdate,
        IF (
            CALCULATE (
                COUNT ( 'Table'[id] ),
                ALLEXCEPT ( 'Table', 'Table'[id] ),
                'Table'[changes] = "x"
            )
                = BLANK (),
            0,
            CALCULATE (
                COUNT ( 'Table'[id] ),
                ALLEXCEPT ( 'Table', 'Table'[id] ),
                'Table'[changes] = "x"
            )
        ),
        BLANK ()
    )

vluwangmsft_0-1663062767376.png

 

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

 

Best Regards,
Lucien

View solution in original post

6 REPLIES 6
v-luwang-msft
Community Support
Community Support

Hi @Anonymous ,

Pls use the below dax to create a new column:

n change1 =
VAR maxdate =
    CALCULATE ( MAX ( 'Table'[start date] ), ALLEXCEPT ( 'Table', 'Table'[id] ) )
RETURN
    IF (
        'Table'[start date] = maxdate,
        IF (
            CALCULATE (
                COUNT ( 'Table'[id] ),
                ALLEXCEPT ( 'Table', 'Table'[id] ),
                'Table'[changes] = "x"
            )
                = BLANK (),
            0,
            CALCULATE (
                COUNT ( 'Table'[id] ),
                ALLEXCEPT ( 'Table', 'Table'[id] ),
                'Table'[changes] = "x"
            )
        ),
        BLANK ()
    )

vluwangmsft_0-1663062767376.png

 

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

 

Best Regards,
Lucien

Anonymous
Not applicable

Thanks for your response @v-luwang-msft .
but the changes column doesn't exist in my data model. how can i create it?

Hi @Anonymous ,

Use the following dax to create a new column:

change1 = 
VAR rank1 =
    RANKX (
        FILTER ( ALL ( 'Table' ), 'Table'[id] = EARLIER ( 'Table'[id] ) ),
        'Table'[end date],
        ,
        ASC,
        DENSE
    )
RETURN
    IF (
        rank1 <> 1
            && CALCULATE (
                MAX ( 'Table'[category] ),
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[id] = EARLIER ( 'Table'[id] )
                        && RANKX (
                            FILTER ( ALL ( 'Table' ), 'Table'[id] = EARLIER ( 'Table'[id] ) ),
                            'Table'[end date],
                            ,
                            ASC,
                            DENSE
                        ) = rank1 - 1
                )
            ) <> 'Table'[category],
        "x",
        BLANK ()
    )

 

Output:(And I think the first id=2222 not need "x" )

vluwangmsft_0-1663292820295.png

 

 

Best Regards

Lucien

Anonymous
Not applicable

Hello,
Thanks for your response @lbendlin .
only changes of a new category are important.
any idea how to do this?

Do a distinct count of categories per user and subtract 1

lbendlin
Super User
Super User

User 2222 only changed category twice, not three times.

 

Do you want to report on any changes or only on changes to a new category?

 

Let's say the third line of 9100 would be category 1.  Does this now count as two changes?

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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