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

New forum boards available in Real-Time Intelligence.

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.