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

Calculated Column LTM (Last 12 Months)

Hello - I am trying to create a calculated column (I want to avoid using a measure for this) that will show the LTM if the row meets certain criteria. I have a small example below (attached as well.) I need column E to be the LTM only if the platform is Android and the Type is Annual; otherwise give me customers.  Here is a screen shot of what it would look like in Excel.

Dcurtis7640_0-1665779644484.png

 

Thank you

1 ACCEPTED SOLUTION

Hi,

Write this calculated column formula

Ending customers = if(and(Data[Platform]="Android",Data[Type]="Annual"),CALCULATE(SUM(Data[Customers]),FILTER(Data,Data[Platform]=EARLIER(Data[Platform])&&Data[Type]=EARLIER(Data[Type])&&Data[AsofDate]>=EDATE(EARLIER(Data[AsofDate]),-12)&&Data[AsofDate]<=EARLIER(Data[AsofDate]))),Data[Customers])

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

11 REPLIES 11
Ashish_Mathur
Super User
Super User

Hi,

Share the download link of the MS Excel workbook.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish_Mathur,  thank you for the reply! I am still running into some issues but I think I am close.  Would it be possible to send you a bigger subset of my table?

You are welcome.  Be very clear about the issue you are facing and also show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Here is the code that I used:

Ending customers = if(and('Archive vw_Plus_MonthyPaidSubs_Counts'[subpaymenthandler]="Android",'Archive vw_Plus_MonthyPaidSubs_Counts'[subtype2]="Year"),CALCULATE(SUM('Archive vw_Plus_MonthyPaidSubs_Counts'[Customers]),FILTER('Archive vw_Plus_MonthyPaidSubs_Counts','Archive vw_Plus_MonthyPaidSubs_Counts'[subpaymenthandler]=EARLIER('Archive vw_Plus_MonthyPaidSubs_Counts'[subpaymenthandler])&&'Archive vw_Plus_MonthyPaidSubs_Counts'[subtype2]=EARLIER('Archive vw_Plus_MonthyPaidSubs_Counts'[subtype2])&&'Archive vw_Plus_MonthyPaidSubs_Counts'[AsofDate]>=EDATE(EARLIER('Archive vw_Plus_MonthyPaidSubs_Counts'[AsofDate]),-2)&&'Archive vw_Plus_MonthyPaidSubs_Counts'[AsofDate]<=EARLIER('Archive vw_Plus_MonthyPaidSubs_Counts'[AsofDate]))),'Archive vw_Plus_MonthyPaidSubs_Counts'[Customers])

 

But the running totals don't seem to add up.  I have two tabs to the Google Sheet - the raw data is a copy of the PBI table after I added the code you sent earlier and the pivot tab summaerizes the results - column D on the pivot tab shows my expected result.

Hi,

Your formula is diffeent from the one that i had shared.  My formulas got you the exact result you had shown in your original post.  Now that you have a lot more conditions, please state them clearly on a small dataset and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hello - thank you again! I realized I had to add the condition for the country to be equal when using my larger data set.  Once I added that and changed the EDATE function to go back 11 months instead of 12, I was able to get my desired solution.  Thank you again for all of your help!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi,

Write this calculated column formula

Ending customers = if(and(Data[Platform]="Android",Data[Type]="Annual"),CALCULATE(SUM(Data[Customers]),FILTER(Data,Data[Platform]=EARLIER(Data[Platform])&&Data[Type]=EARLIER(Data[Type])&&Data[AsofDate]>=EDATE(EARLIER(Data[AsofDate]),-12)&&Data[AsofDate]<=EARLIER(Data[AsofDate]))),Data[Customers])

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Shaurya
Memorable Member
Memorable Member

Hi @Dcurtis7640,

 

Use:

 

LTM = IF('Table'[Platform]="Android" && 'Table'[Type]="Annual", 'Table'[Ending Customer], 'Table'[Customer])

 

Works for you? Mark this post as a solution if it does!
Consider taking a look at my blog: Forecast Period - Previous Forecasts

Hi Shaurya - I should have specified, I am trying to generate the ending customer column from the other 4. 

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.