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
Domenick
Helper IV
Helper IV

Why I can't I use TODAY() in calculation?

Hi guys,

 

I'm trying to sum a column for a specific relative date range. Basically, I want to eventually calculate an average over the the 6 weeks prior to last week. (I want a show "last 6 weeks average," but I can't use the current week because current week's data is posted at the end of the week and therefor unreliable).

 

When I try creating a measure like this, it says I can't use the TODAY() function nor a measure. 

 

Total Six Week Labor Spend = CALCULATE(SUM('LD (My Projects)'[BillExt]),
                                                 'LD (My Projects)'[TransDate]>DATEADD(TODAY(),49,DAY),
                                                 'LD (My Projects)'[TransDate]<DATEADD(TODAY(),7,DAY)
                                                 )
 
Any ideas?
1 ACCEPTED SOLUTION
v-kkf-msft
Community Support
Community Support

Hi @Domenick ,

 

Please try the following formula:

 

Total Six Week Labor Spend = 
VAR CurrentWeekStart =
    TODAY () - WEEKDAY ( TODAY (), 2 ) + 1
RETURN
    CALCULATE (
        SUM ( 'LD (My Projects)'[BillExt] ),
        FILTER (
            'LD (My Projects)',
            'LD (My Projects)'[TransDate] >= CurrentWeekStart - 42
                && 'LD (My Projects)'[TransDate] < CurrentWeekStart
        )
    )        

vkkfmsft_0-1648704407140.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
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-kkf-msft
Community Support
Community Support

Hi @Domenick ,

 

Please try the following formula:

 

Total Six Week Labor Spend = 
VAR CurrentWeekStart =
    TODAY () - WEEKDAY ( TODAY (), 2 ) + 1
RETURN
    CALCULATE (
        SUM ( 'LD (My Projects)'[BillExt] ),
        FILTER (
            'LD (My Projects)',
            'LD (My Projects)'[TransDate] >= CurrentWeekStart - 42
                && 'LD (My Projects)'[TransDate] < CurrentWeekStart
        )
    )        

vkkfmsft_0-1648704407140.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

johnt75
Super User
Super User

You can't use TODAY because DATEADD needs a column of values, not a single value. Try

Total Six Week Labor Spend = CALCULATE(SUM('LD (My Projects)'[BillExt]),
'LD (My Projects)'[TransDate]>TODAY() - 49,
'LD (My Projects)'[TransDate]<TODAY() - 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.