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
mikemi
Frequent Visitor

DAX formula to show a value for the same day of the week over the past six weeks (by week)

I stitched together a measure "Trials Last Week" that shows values for last Sunday (coming from a Salesforce snapshot report that has dozens of rows for every day over the past few months). I created two boolean calculated columns "isLastWeek" (at the bottom of this post) and "Day" to use as filters in the measure.

 

How do I create versions of "isLastWeek" for two Sundays ago, three Sundays ago...eight Sundays ago so I can match them to measures for the same number of weeks ago? I know creating several calculated columns and measures isn't the cleanest approach, but it's fine for now.

 

Trials Last Week = 
CALCULATE (
    COUNTA ( 'Daily Snapshot'[Stage] ),
    'Daily Snapshot'[Stage] = "4. Trial",
    'Daily Snapshot'[isLastWeek] = TRUE (),
    'Daily Snapshot'[Day] = "Sunday",
    'Daily Snapshot'[Status] <> "Inactive"
)
Day =
FORMAT ( 'Daily Snapshot'[Date], "DDDD" )
isLastWeek = 
IF (
    WEEKNUM ( TODAY (), 1 ) = 1,
    IF (
        AND (
            YEAR ( 'Daily Snapshot'[Date] )
                = YEAR ( TODAY () ) - 1,
            WEEKNUM ( 'Daily Snapshot'[Date] )
                = WEEKNUM ( DATE ( YEAR ( TODAY () ), MONTH ( 12 ), DAY ( 31 ) ) )
        ),
        TRUE (),
        FALSE ()
    ),
    IF (
        AND (
            YEAR ( 'Daily Snapshot'[Date] ) = YEAR ( TODAY () ),
            WEEKNUM ( 'Daily Snapshot'[Date], 1 ) = WEEKNUM ( TODAY (), 1 )
        ),
        TRUE (),
        FALSE ()
    )
) 

 

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

hi,@mikemi

   You can use your measure isLastWeek do these with a little modification as below:

isLastWeek2 = 
IF (
    WEEKNUM ( TODAY (), 1 ) = 1,
    IF (
        AND (
            YEAR ( 'Daily Snapshot'[Date] )
                = YEAR ( TODAY () ) - 1,
            WEEKNUM ( 'Daily Snapshot'[Date] )
                = WEEKNUM ( DATE ( YEAR ( TODAY () ), MONTH ( 12 ), DAY ( 31 ) ) )
        ),
        TRUE (),
        FALSE ()
    ),
    IF (
        AND (
            YEAR ( 'Daily Snapshot'[Date] ) = YEAR ( TODAY () ),
            WEEKNUM ( 'Daily Snapshot'[Date], 1 )+1 = WEEKNUM ( TODAY (), 1 )
        ),
        TRUE (),
        FALSE ()
    )
) 

 

Result:

9.PNG 

Be careful where the red box line is marked:

10.PNG

Best Regards,

Lin

 

 

 

Community Support Team _ Lin
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

2 REPLIES 2
v-lili6-msft
Community Support
Community Support

hi,@mikemi

   You can use your measure isLastWeek do these with a little modification as below:

isLastWeek2 = 
IF (
    WEEKNUM ( TODAY (), 1 ) = 1,
    IF (
        AND (
            YEAR ( 'Daily Snapshot'[Date] )
                = YEAR ( TODAY () ) - 1,
            WEEKNUM ( 'Daily Snapshot'[Date] )
                = WEEKNUM ( DATE ( YEAR ( TODAY () ), MONTH ( 12 ), DAY ( 31 ) ) )
        ),
        TRUE (),
        FALSE ()
    ),
    IF (
        AND (
            YEAR ( 'Daily Snapshot'[Date] ) = YEAR ( TODAY () ),
            WEEKNUM ( 'Daily Snapshot'[Date], 1 )+1 = WEEKNUM ( TODAY (), 1 )
        ),
        TRUE (),
        FALSE ()
    )
) 

 

Result:

9.PNG 

Be careful where the red box line is marked:

10.PNG

Best Regards,

Lin

 

 

 

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

Thank you! This worked.

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.