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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Amos_Mc
New Member

How do I create "Result from Prior Month"

I want to monitor the movement of clients who have moved from an "Onboarding" state to a "Retain & Grow" state
I have reviewed previous posts and yet I am unable to create the required result

Here is the DAX I am using right now

State Prior Month = CALCULATE (
    MAX ( 'Customer Life Cycle State'[State Name] ),
    FILTER ( 'Date', 'Date'[Month Number] =  ('Date'[Month Number]) - 1 )
)


Sample table extract below with result of current DAX showing the same state as current

Client IDMonth YearMonth NumberState Name (Current Month)State Name (Prior Month)Performing Advertiser Flag Result needed for PRIOR Month
12345Jun-226ONBOARDINGONBOARDING1 ONBOARDING
12345Jul-227ONBOARDINGONBOARDING1 ONBOARDING
12345Aug-228ONBOARDINGONBOARDING1 ONBOARDING
12345Sep-229RETAIN & GROWRETAIN & GROW1 ONBOARDING
12345Oct-2210RETAIN & GROWRETAIN & GROW1 RETAIN & GROW
12345Nov-2211RETAIN & GROWRETAIN & GROW1 RETAIN & GROW
12345Dec-2212RETAIN & GROWRETAIN & GROW1 RETAIN & GROW
12345Jan-231RETAIN & GROWRETAIN & GROW1 RETAIN & GROW
12345Feb-232RETAIN & GROWRETAIN & GROW1 RETAIN & GROW
12345Mar-233RETAIN & GROWRETAIN & GROW1 RETAIN & GROW
8 REPLIES 8
eliasayyy
Super User
Super User

great news! i found a solution by measure

first add the month id column(this will help you for later when theres multiple years and same month number)

use this measure

 

 

 

Measure = 
VAR ThisMonthID =
    MAX ( 'Table'[Month ID] )
VAR result =
    CALCULATE (
        MAX ( 'Table'[Status] ),ALLEXCEPT('Table'[Client ID]),
        'Table'[Month ID] = ThisMonthID - 1
    )
RETURN
IF(ISBLANK(result),"",result)

 

 


the all except will filter out all the columns and keep the main focus on client ID so if you want to be making it by Client id and a sub category , add the sub category to the ALLEXCEPT expression

 

and i added another client id just in case if you have multple and switch the sate name a bit

annonymous1999_0-1683036025320.png

a kudos would be appreciated

eliasayyy
Super User
Super User

hello i dont know how to do it in measure but it can be done with calculated column

step 1 :
add month id index 

VAR _min = YEAR(MIN('Table'[Date]))
RETURN
MONTH('Table'[Date]) + (YEAR('Table'[Date]) - _min) *12

 

Step 2 
add a new column with the expressions

Previous Return = CALCULATE(MAX('Table'[State Name]),FILTER('Table','Table'[Month ID] = EARLIER('Table'[Month ID]) -1 ))


Result:

annonymous1999_0-1683011616901.png

 



Thanks for your suggestion
I tried applying this solution using the DAX below and I was unable to get the desired result

It still delivered the current month status not the prior month

State99 =
VAR ThisMonthID =
    MAX ('Date'[Month Number] )
VAR result =
    CALCULATE (
        MAX ('Customer Life Cycle State'[State Name] ),ALLEXCEPT('Advertiser',Advertiser[Advertiser CID]),
        'Date'[Month Number] = ThisMonthID - 1
    )
RETURN
IF(ISBLANK(result),"",result)
Amos_Mc_0-1683514266927.png

 

Please check my solution i advised to create a new calculated column called momth id and use month id instead of month number

I would have liked to use your column solution. Unfortunately I am using a live connect and even with a limited composite model I am unable to add a column to my large dataset. 

ValtteriN
Super User
Super User

Hi,

Here is one way to do this:

Measure 47 =
CALCULATE ( MAX('Table (32)'[State Name (Current Month)]), DATEADD ( 'Calendar'[Date], -1, MONTH ) )

End result:
ValtteriN_0-1683011299356.png

 

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks for your suggestion
I tried applying this solution using the DAX below and I was unable to get the desired result

It still delivered the current month status not the prior month


State 47 ver =
CALCULATE ( MAX ('Customer Life Cycle State'[State Name]), DATEADD ( 'Date'[Calendar Date], - 1 , MONTH ) )

Thanks for your suggestion
I tried applying this solution using the DAX below and I was unable to get the desired result

It still delivered the current month status not the prior month

State 47 ver = CALCULATE ( MAX ('Customer Life Cycle State'[State Name]), DATEADD ( 'Date'[Calendar Date], - 1 , MONTH ) )
Amos_Mc_0-1683514266927.png

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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