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
MightyMicrobe
Helper II
Helper II

Previous week results calculation on a week key

This has been asked to death, but none of the previous solutions seems to work for me, please help. 

My metric is grouped by Week End label in the calendar table (WE2019-07-05, for example). 

In my calendar table I have the label and the label keys for the week end, like so:

MightyMicrobe_1-1623592459334.png

I'm trying to use the following formula which does not work. What am I doing wrong?

Visits PW = 
CALCULATE(
    [Total Visits],
    FILTER(
        ALL('Calendar'), 
        'Calendar'[Week Ending Date Key] = 'Calendar'[Week Ending Date Key] - 1
    )
)

 

1 ACCEPTED SOLUTION
v-xulin-mstf
Community Support
Community Support

Hi @MightyMicrobe

 

You need to modify the measure to:

Visits PW =
VAR WeekEndingDateKey = MIN('Calendar'[Week Ending Date Key])
RETURN
CALCULATE(
    [Total Visits],
    FILTER(
        ALL('Calendar'), 
        'Calendar'[Week Ending Date Key] = WeekEndingDateKey - 7
    )
)

If you still have some question, please don't hesitate to let me known.‌‌

 

Best Regards,

Link

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

View solution in original post

4 REPLIES 4
v-xulin-mstf
Community Support
Community Support

Hi @MightyMicrobe

 

You need to modify the measure to:

Visits PW =
VAR WeekEndingDateKey = MIN('Calendar'[Week Ending Date Key])
RETURN
CALCULATE(
    [Total Visits],
    FILTER(
        ALL('Calendar'), 
        'Calendar'[Week Ending Date Key] = WeekEndingDateKey - 7
    )
)

If you still have some question, please don't hesitate to let me known.‌‌

 

Best Regards,

Link

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

notem
Frequent Visitor

@MightyMicrobe , because of for every row in a table there are checking condition:

'Calendar'[Week Ending Date Key] = 'Calendar'[Week Ending Date Key] - 1

For example, 'Calendar'[Week Ending Date Key] = 20190712, then condition will be

20190712 = 20190712 - 1

So it's always FALSE for every row in table.
Solution:

Visits PW =
VAR WeekEndingDateKey = MIN('Calendar'[Week Ending Date Key])
RETURN
CALCULATE(
    [Total Visits],
    FILTER(
        ALL('Calendar'), 
        'Calendar'[Week Ending Date Key] = WeekEndingDateKey - 1
    )
)

Thanks for this. I tried the solution, and while there are no errors, the formula returns blanks in the matrix. 

MightyMicrobe_0-1623631484784.png

 

@MightyMicrobe, oops!

'Calendar'[Week Ending Date Key] = WeekEndingDateKey - 7

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.