cancel
Showing results 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.

Frequent Visitor

## Flag for last year same period

I have a table with columns , End date period(end date of each period),Start date period(Start date of each period), Period (YYYY-YYYY PXX) .
I have created a measure to identify current year current period(2023-2024 P12) and current year last period(2023-2024 P11).
Current Year Last Period =
VAR MaxDate = MAXX(FILTER('Hold Date', 'Hold Date'[PERIOD_END_DT] + 1 < TODAY()), 'Hold Date'[Release Period])
VAR Year1 = LEFT(MaxDate, 4)
VAR Year2 = MID(MaxDate, 6, 4)
VAR Period = MID(MaxDate, 12, 2)
RETURN
Year1 & "-" & Year2 & " P" & Period
CurrentPeriod =
VAR CurrentDate = TODAY()
RETURN
MAXX(
FILTER(
'Hold Date',
'Hold Date'[PERIOD_START_DT] <= CurrentDate && 'Hold Date'[PERIOD_END_DT] >= CurrentDate
),
'Hold Date'[Release Period]
)

I want to create a flag to mark Current year Current Period as 1 till Last Year Current period.
the out put should be like this

 Period Flag 2022-2023 P5 0 2022-2023 P6 0 2022-2023 P7 0 2022-2023 P8 0 2022-2023 P9 0 2022-2023 P10 0 2022-2023 P11 0 2022-2023 P12 1 2022-2023 P13 1 2023-2024 P1 1 2023-2024 P2 1 2023-2024 P3 1 2023-2024 P4 1 2023-2024 P5 1 2023-2024 P6 1 2023-2024 P7 1 2023-2024 P8 1 2023-2024 P9 1 2023-2024 P10 1 2023-2024 P11 1 2023-2024 P12 1 2023-2024 P13 0 2024-2025 P1 0

2 REPLIES 2
Super User

Hello @nemo189,

Can you please try this DAX:

``````Period Flag =
VAR CurrentPeriod =
[CurrentPeriod]
VAR LastYearCurrentPeriod =
CALCULATE(
[Current Year Last Period],
)
VAR CurrentPeriodDate =
MAX('Hold Date'[PERIOD_END_DT])comparison
VAR IsWithinRange =
CurrentPeriodDate >= CALCULATE(MIN('Hold Date'[PERIOD_END_DT]), 'Hold Date'[Release Period] = LastYearCurrentPeriod)
&& CurrentPeriodDate <= CALCULATE(MAX('Hold Date'[PERIOD_END_DT]), 'Hold Date'[Release Period] = CurrentPeriod)
RETURN
IF(IsWithinRange, 1, 0)
``````

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution?
➤ Lets connect on LinkedIn: Join my network of 13K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning
Super User

Have you considered using the SAMEPERIODLASTYEAR convenience function?

Announcements

#### 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

#### Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

#### Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors