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
ivandelgra
Helper I
Helper I

Count Status change Year over Year

Hello I have this dataset:

 

INDEXID PERSONCARD TYPESUBSCRIPTION YEAR
1AFREE2018
2BPREMIUM2018
3CFREE2018
4DPRO2018
5APREMIUM2019
6BPRO2019
7CPRO2019
8EFREE2019
9DFREE2020
10EPRO2020

 

I would like to know for each year (from 2018 to 2019):

  • how many FREE subscribers have changed their plan to PRO subscribers
  • how many FREE subscribers have not changed their plan
  • how many FREE subscribers have changed their plan to PREMIUM subscribers

I need of course the other combinations, too. 

"Index" column gives the chronological sequence of events.
 
Can you help me? Maybe can we use DAX in CALCULATED COLUMN and maybe row context thoughts are the right direction, but I don't know what kind of formula enter (I have seen something with earlier... Could be?)
 
Anyway I have 1,5 million row, so some formulas, if too complicated, could not work.
 

 

HELP ME PLEASE!!!

1 ACCEPTED SOLUTION

Minor change required:

 

Change = 
    VAR __Current = [CARD TYPE]
    VAR __Previous = 
        FILTER(
            'Query1',
            [ID PERSON] = EARLIER([ID PERSON]) && 
                [INDEX] < EARLIER([INDEX])
        )
    VAR __LastID = MAXX(__Previous,[INDEX])
    VAR __Last = IF(ISBLANK(__LastID),BLANK(),MAXX(FILTER('Query1',[INDEX] = __LastID),[CARD TYPE]))
RETURN
    SWITCH(TRUE(),
        ISBLANK(__Last),BLANK(),
        __Current <> __Last, __Last & " to " & __Current,
        BLANK()
    )

 

I don't typically use an Index starting at 0 because of issues like this.


@ 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

8 REPLIES 8
Greg_Deckler
Super User
Super User

Please don't cross post.

 

Change = 
    VAR __Current = [CARD TYPE]
    VAR __Previous = 
        FILTER(
            'Table',
            [ID PERSON] = EARLIER([ID PERSON]) && 
                [INDEX] < EARLIER([INDEX])
        )
    VAR __LastID = MAXX(__Previous,[INDEX])
    VAR __Last = MAXX(FILTER('Table',[INDEX] = __LastID),[CARD TYPE])
RETURN
    SWITCH(TRUE(),
        ISBLANK(__Last),BLANK(),
        __Current <> __Last, __Last & " to " & __Current,
        BLANK()
    )

 


@ 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...

Thank you so much @Greg_Deckler, but it actually doesn't guess right the correct result

 

Moreover, it is strange but even if some row has blank ID Person, the formula returns some result.

 

How is it possible since I want to understand the same person which plan type he changed to?

 

Thank you for your patience.

Unclear @ivandelgra it seems to work just fine in the attached PBIX so perhaps there is something that you are not telling me. The code looks at the most recent Index for an ID PERSON. If the status is not the same, it logs it correctly. Otherwise, it puts in a blank. So this would handle people changing even within the same year. What are you expected results from the sample data? 

 

INDEXID PERSONCARD TYPESUBSCRIPTION YEARChange

1 A FREE 2018  
2 B PREMIUM 2018  
3 C FREE 2018  
4 D PRO 2018  
5 A PREMIUM 2019 FREE to PREMIUM
6 B PRO 2019 PREMIUM to PRO
7 C PRO 2019 FREE to PRO
8 E FREE 2019  
9 D FREE 2020 PRO to FREE
10 E PRO 2020 FREE to PRO

@ 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...

Here attached the file with my data set after having integrated your formula. 

I have filtered a single ID Person so you can note the error immediately.

 

Powerbi file:

https://drive.google.com/file/d/1GsWFg27PnacVkptezuTFSSIAVLSQL95E/view?usp=sharing

 

Dataset source:

https://drive.google.com/file/d/1QpMbP5tNbxN1UsfpQKaNg0RZWTmruQGQ/view?usp=sharing

 

Thank you @Greg_Deckler .

Minor change required:

 

Change = 
    VAR __Current = [CARD TYPE]
    VAR __Previous = 
        FILTER(
            'Query1',
            [ID PERSON] = EARLIER([ID PERSON]) && 
                [INDEX] < EARLIER([INDEX])
        )
    VAR __LastID = MAXX(__Previous,[INDEX])
    VAR __Last = IF(ISBLANK(__LastID),BLANK(),MAXX(FILTER('Query1',[INDEX] = __LastID),[CARD TYPE]))
RETURN
    SWITCH(TRUE(),
        ISBLANK(__Last),BLANK(),
        __Current <> __Last, __Last & " to " & __Current,
        BLANK()
    )

 

I don't typically use an Index starting at 0 because of issues like this.


@ 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...
Anonymous
Not applicable

@Greg_Deckler Is this the formula i would need for mine? my response to @amitchandak to confirm exactly what im trying to do

 

THANK YOU

 

 

@Greg_Deckler YOU ARE A GENIOUS!!! WOOOW! 

 

I have made some minor change, too in order to include the result for people that does not change YoY.

 

Below you can find the final formula. thank you Greeeeeeeeeeeeg

 

Change =
VAR __Current = [CARD TYPE]
VAR __Previous =
FILTER(
'Query1';
[ID PERSON] = EARLIER([ID PERSON]) &&
[INDEX] < EARLIER([INDEX])
)
VAR __LastID = MAXX(__Previous;[INDEX])
VAR __Last = IF(ISBLANK(__LastID);BLANK();MAXX(FILTER('Query1';[INDEX] = __LastID);[CARD TYPE]))
RETURN
SWITCH(TRUE();
ISBLANK(__Last);BLANK();
__Current <> __Last || __Current = __Last ; __Last & " to " & __Current;
BLANK()
)
 

You're welcome! Happy 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