Losing my mind...can someone tell me what's wrong?

rilzniak

Active Member
Joined
Jul 20, 2012
Messages
293
I'm trying to write a measure in Power Pivot for the current year through the last date I have data for (Jan. 17, 2025). I also want to do the same for the prior year (code below). The results are connected to a year slicer. I'm getting an error - The formula contains an invalid character '['. - on the line "SUM('Data'[Sales])," and I have no idea why. I've tried with and without the quotes but it doesn't resolve the issue. Any ideas?

Rich (BB code):
=
VAR CurrentDate = MAX('Calendar'[Date])
VAR StartOfMonth = DATE(YEAR(CurrentDate), MONTH(CurrentDate), 1)

VAR PriorYearStartOfMonth = DATE(YEAR(CurrentDate) - 1, MONTH(CurrentDate), 1)
VAR PriorYearEndOfMonth = EOMONTH(PriorYearStartOfMonth, 0)

VAR IsFutureMonth = CurrentDate > [Last Sales Date]

RETURN
    IF(
        IsFutureMonth,
        -- Future month: Return full prior year's month sales
        CALCULATE(
            SUM('Data'[Sales]),
            FILTER(
                'Data',
                'Data'[Date] >= PriorYearStartOfMonth &&
                'Data'[Date] <= PriorYearEndOfMonth
            )
        ),
        -- Current month or earlier: Return MTD sales
        CALCULATE(
            SUM('Data'[Sales]),
            FILTER(
                'Data',
                'Data'[Date] >= StartOfMonth &&
                'Data'[Date] <= [Last Sales Date]
            )
        )
    )
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Remove the comments, and use a different name to StartOfMonth as that is a DAX function.
 
Upvote 0
Remove the comments, and use a different name to StartOfMonth as that is a DAX function.
Thanks Rory. The formula works for years prior to 2025 but when I select the '2025' Year slicer, I get a blank. The purpose was for me to show 2025 actuals through the most recent date I have data for and also 2024 actuals through the same day and month.

Do you have any suggestions as to what I've done wrong?
 
Upvote 0

Forum statistics

Threads
1,226,114
Messages
6,189,051
Members
453,522
Latest member
Seeker2025

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top