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

Last 4 weeks Year on Year

Am calculating year on year based on last 4 weeks. My issue is for some reason my calculation seems to stop working as soon as i filter, i am working with Start of Week dates which makes it a little bit of a pain;

 

Last 4 weeks = CALCULATE(SUM(Revenue[Cost]), DATESINPERIOD(Revenue[Start of Week Date],MAX(Revenue[Start of Week Date]),-27,DAY))
 
Last 4 weeks Last Year for Comparison = CALCULATE(SUM(Revenue[Cost]), DATESINPERIOD(Revenue[Start of Week Date],(MAX(Revenue[Start of Week Date])-365),-27,day))
 
 
What am i doing wrong here?
1 ACCEPTED SOLUTION
v-chenwuz-msft
Community Support
Community Support

Hi @Anonymous ,

 

The problem is the DATESINPERIOD(). The table Revenue inputed to DATESINPERIOD to be calculated has been filtered by field in the visual. So the result of DATESINPERIOD is not all Revenue table.

For example , the result of MAX(Revenue[Start of Week Date]) is 2021/11/19, then the result of DATESINPERIOD will be 2021/11/1 to 2021/11/19 instead of 2021/10/24.

vchenwuzmsft_0-1637287002418.png

 

May be you can try FILTER() instead of DATESINPERIOD().

Last 4 weeks =
CALCULATE(
    SUM( Revenue[Cost] ),
    FILTER(
        ALL( Revenue ),
        Revenue[Start of Week Date]
            >= MAX( Revenue[Start of Week Date] ) - 27
            && Revenue[Start of Week Date] <= MAX( Revenue[Start of Week Date] )
    )
)

 

If I misunderstood you please let me know. And you can share some example data without sensitive data.

 

Best Regards

Community Support Team _ chenwu zhu

 

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

1 REPLY 1
v-chenwuz-msft
Community Support
Community Support

Hi @Anonymous ,

 

The problem is the DATESINPERIOD(). The table Revenue inputed to DATESINPERIOD to be calculated has been filtered by field in the visual. So the result of DATESINPERIOD is not all Revenue table.

For example , the result of MAX(Revenue[Start of Week Date]) is 2021/11/19, then the result of DATESINPERIOD will be 2021/11/1 to 2021/11/19 instead of 2021/10/24.

vchenwuzmsft_0-1637287002418.png

 

May be you can try FILTER() instead of DATESINPERIOD().

Last 4 weeks =
CALCULATE(
    SUM( Revenue[Cost] ),
    FILTER(
        ALL( Revenue ),
        Revenue[Start of Week Date]
            >= MAX( Revenue[Start of Week Date] ) - 27
            && Revenue[Start of Week Date] <= MAX( Revenue[Start of Week Date] )
    )
)

 

If I misunderstood you please let me know. And you can share some example data without sensitive data.

 

Best Regards

Community Support Team _ chenwu zhu

 

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

 

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.