Forum Discussion
How to create same period last year without date column. only with month and year
| Account | month year | Value |
| A | Jan-23 | 5389 |
| B | Jan-23 | 6450 |
| C | Jan-23 | 6159 |
| A | Jan-24 | 5797 |
| B | Jan-24 | 6381 |
| C | Jan-24 | 5993 |
| A | Jan-25 | 5274 |
| B | Jan-25 | 6049 |
| C | Jan-25 | 6511 |
Hi,
PBI file attached.
Hope this helps.
7 Replies
- GeraldGEmerick
Memorable Member
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 - Ashish_Mathur
Super User
- d_m_LNK
Super User
You could create a calculated column to create the EOM date based on your Month Year column and then you could use that one?
- danextian
Super User
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.
- ThxAlot
Super User
- krishnakanth240
Super User
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!
- v-pnaroju-msft
Community Support
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.