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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.