Forum Discussion

ArpitaRampur's avatar
ArpitaRampur
Regular Visitor
9 months ago
Solved

How to create same period last year without date column. only with month and year

Account month yearValue
AJan-235389
BJan-236450
CJan-236159
AJan-245797
BJan-246381
CJan-245993
AJan-255274
BJan-256049
CJan-256511

7 Replies

  • ArpitaRampur Here is a measure that does that:

    Last Year = 
    VAR _MY = MAX( 'Table'[month year] )
    VAR _Month = LEFT( _MY, 4 )
    VAR _Year = RIGHT( _MY, 2 ) + 0
    VAR _LY = _Year - 1
    VAR _LYMY = _Month & _LY
    VAR _Return = CALCULATE( SUM( 'Table'[Value] ), 'Table'[month year] = _LYMY )
    RETURN _Return
  • You could create a calculated column to create the EOM date based on your Month Year column and then you could use that one?

  • Hi ArpitaRampur 

    You can simplify time inteligence calculations by creating a date equivalent column of your month-year which is either the start or end of month.

    Since there is already a date column, you may now use SAMEPERIODLASTYEAR

    Previous Year = 
    CALCULATE (
        [Amount],
        SAMEPERIODLASTYEAR ( 'Table'[Period Start Date] ),
        REMOVEFILTERS ( 'Table'[Period Start Date], 'Table'[month year] )
    )
    

    Please note that since, everything is in a single table, you must apply REMOVEFILTERS to all dim columns added to the visual. You can avoid this by maintaining a separate dates table marked as date. 

     

    Please see the attached pbix.

  • Hi ArpitaRampur 

     

    Create a calculated YearMonth key + DAX lookup

    > Create a numeric YearMonth column in your fact table:

    YearMonthKey = Fact[Year] * 100 + Fact[MonthNo]
    (Use MonthNo = Jan=1, Feb=2, etc.)

    > Create Same Period Last Year measure
    SPLY =
    VAR CurrentYear = MAX ( Fact[Year] )
    VAR CurrentMonth = MAX ( Fact[MonthNo] )
    RETURN
    CALCULATE (
    SUM ( Fact[Value] ),
    Fact[Year] = CurrentYear - 1,
    Fact[MonthNo] = CurrentMonth
    )

    Result
    Account Month-Year Value SPLY
    A Jan-24 5797 5389
    B Jan-24 6381 6450
    C Jan-24 5993 6159
    A Jan-25 5274 5797
    B Jan-25 6049 6381
    C Jan-25 6511 5993

    > If Month is stored as text (Jan-23)
    Create Month Number column
    MonthNo =
    SWITCH (
    LEFT ( Fact[MonthYear], 3 ),
    "Jan", 1,
    "Feb", 2,
    "Mar", 3,
    "Apr", 4,
    "May", 5,
    "Jun", 6,
    "Jul", 7,
    "Aug", 8,
    "Sep", 9,
    "Oct", 10,
    "Nov", 11,
    "Dec", 12
    )


    Then extract year:
    Year = 2000 + RIGHT ( Fact[MonthYear], 2 )

     

    Please give headsup / mark it as a solution once it is completed. Thank You!

  • Thankyou, d_m_LNK, GeraldGEmerick, Ashish_Mathur, danextian , ThxAlot and krishnakanth240 for your responses.

    Hi ArpitaRampur,

    We appreciate your inquiry through the Microsoft Fabric Community Forum.

    We would like to inquire whether have you got the chance to check the solutions provided by d_m_LNK, GeraldGEmerick, Ashish_Mathur, danextian , ThxAlot and krishnakanth240to resolve the issue. We hope the information provided helps to clear the query. Should you have any further queries, kindly feel free to contact the Microsoft Fabric community.

    Thank you.