Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Anonymous
Not applicable

How to create a Last 4 Week flag for calendar table that works across multiple fiscal years

I need to show how a few metrics (forecast accuracy, etc...) performed Fiscal Year to Date, as well as in the L4W (Last Four Weeks).

My current solution is to have separate sets of measures to accomplish this.

First set is regular measures and I filter their visuals to Fiscal Year to Date, a column I have built into my calendar table written in M. Great! The second set though, I don't know how to create a similar flag that flags the date in the calendar table if it falls in the last four weeks (from current date) of any given fiscal year. I have a separate set of measures designated L4W, which uses DATEADD to create a table of the last 28 days.

For example, Last Four Weeks from today() is today and the preceding 28 days. So the calendar dates March 19th thru and including April 16th. I want to create a flag column in my calendar table that denotes 3/19 thru 4/16 of all Fiscal Years, so that I can reuse the same measures and put a "L4W" filter on the visuals to accomplish my goal. Any thoughts on how best to do this?

Edit: I figured out the flag to designate which rows of the calendar table are in the last four weeks from a specified date (specified date is called "Complete POS Date Literal")

Flag_L4W = 
    VAR POSValidToDate = 'Calendar'[Complete POS Date Literal]
    VAR POSValidFromDate = 'Calendar'[Complete POS Date Literal]-27
    VAR POSL4WValid = IF(AND('Calendar'[Date]<=POSValidToDate,'Calendar'[Date]>=POSValidFromDate),TRUE,FALSE)
    RETURN
    POSL4WValid

This achieves a TRUE when the row was in the last four weeks from the Complete POS Date Literal date.

How do I extend this to apply to the same range of calendar days but from previous years as well?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Happened upon a solution that works for me:

 

Flag_L4W =

VAR POSValidToDate = 'Calendar'[Complete POS Date Literal]

VAR POSValidFromDate = 'Calendar'[Complete POS Date Literal] - 27

VAR StartMonthDay = FORMAT(POSValidFromDate, "MM-DD")

VAR EndMonthDay = FORMAT(POSValidToDate, "MM-DD")

VAR CurrentMonthDay = FORMAT('Calendar'[Date], "MM-DD")

VAR POSL4WValid =

IF(

AND(

CurrentMonthDay >= StartMonthDay,

CurrentMonthDay <= EndMonthDay

),

TRUE,

FALSE

)

RETURN

POSL4WValid

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Happened upon a solution that works for me:

 

Flag_L4W =

VAR POSValidToDate = 'Calendar'[Complete POS Date Literal]

VAR POSValidFromDate = 'Calendar'[Complete POS Date Literal] - 27

VAR StartMonthDay = FORMAT(POSValidFromDate, "MM-DD")

VAR EndMonthDay = FORMAT(POSValidToDate, "MM-DD")

VAR CurrentMonthDay = FORMAT('Calendar'[Date], "MM-DD")

VAR POSL4WValid =

IF(

AND(

CurrentMonthDay >= StartMonthDay,

CurrentMonthDay <= EndMonthDay

),

TRUE,

FALSE

)

RETURN

POSL4WValid

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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