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
tomislav_mi
Helper II
Helper II

Same period last year calculated column based on a condition

Hey guys,

I am struggling with how to get one challenging calculated column. I appreciate every help I can get.

This is my data set and the desired calculated column is in orange.

So, I am trying to compare Ending MRR of every customer and it's Ending MRR in the same period last year, and if the previous year Ending MRR is blank, I would need to get current Ending MRR.

Basically, I want to test is there any customer who was not active last year and is active now.

CustomerReport DateEnding MRRSame period last year MRR
A2/28/2019236 
A3/31/2019236 
A4/30/2019236 
A12/31/2019  
B6/30/2018  
B7/31/2018  
B8/31/2018  
B9/30/2018  
B10/31/2018  
B11/30/2018  
B12/31/2018  
B1/31/2019  
B2/28/2019  
B3/31/2019  
B4/30/2019  
B5/31/2019  
B6/30/2019  
B7/31/2019  
B8/31/2019316316
B9/30/2019316316
B10/31/2019316316
B11/30/2019316316
B12/31/2019316316
B1/31/2020316316
B2/29/2020316316

 


Any help is welcome.

Thanks!

 

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @tomislav_mi ,

 

Try this:

Same period last year MRR = 
VAR MinDateofEachCustomer =
    MINX ( ALLEXCEPT ( 'Table', 'Table'[Customer] ), 'Table'[Report Date] )
VAR LastYearValue =
    CALCULATE (
        SUM ( 'Table'[Ending MRR] ),
        ALLEXCEPT ( 'Table', 'Table'[Customer] ),
        SAMEPERIODLASTYEAR ( 'Table'[Report Date] )
    )
RETURN
    IF (
        MinDateofEachCustomer < SAMEPERIODLASTYEAR ( 'Table'[Report Date] ),
        IF ( LastYearValue = BLANK (), 'Table'[Ending MRR], LastYearValue )
    )

mrr.PNG

 

 

Best Regards,

Icey

 

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

6 REPLIES 6
Icey
Community Support
Community Support

Hi @tomislav_mi ,

 

Try this:

Same period last year MRR = 
VAR MinDateofEachCustomer =
    MINX ( ALLEXCEPT ( 'Table', 'Table'[Customer] ), 'Table'[Report Date] )
VAR LastYearValue =
    CALCULATE (
        SUM ( 'Table'[Ending MRR] ),
        ALLEXCEPT ( 'Table', 'Table'[Customer] ),
        SAMEPERIODLASTYEAR ( 'Table'[Report Date] )
    )
RETURN
    IF (
        MinDateofEachCustomer < SAMEPERIODLASTYEAR ( 'Table'[Report Date] ),
        IF ( LastYearValue = BLANK (), 'Table'[Ending MRR], LastYearValue )
    )

mrr.PNG

 

 

Best Regards,

Icey

 

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

Thank you all guys, @Icey @amitchandak @Mariusz 

when I combined all I have read I got sollution!

Thanks all!

amitchandak
Super User
Super User

Something like this

 


if ( isblank(CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],0,Year)) ),
CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],0,Year))

CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year)))

Mariusz
Community Champion
Community Champion

Hi @tomislav_mi 

 

try SAMEPERIODLASTYEAR() function.
https://docs.microsoft.com/en-us/dax/sameperiodlastyear-function-dax

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Hey @Mariusz ,

already tried to use it withing CALCULATE but it does not work. I could get limited solution when using it as a measure but not as a calculated column.

Hi @tomislav_mi 

 

When using a column add ALLEXCEPT( yourtable, yourtable[customerColumn ) to you CALCULATE as an extra argument 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

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.