This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreLevel up your Power BI skills this month - build one visual each week and tell better stories with data! Get started
Hello,
I'm trying to get LY YTD sales writing this formula. I can confirm the Total Sales YTD formula works, but when I try to use the formula below I'm getting sales totals through the end of February 2021 instead of through February 7th, 2021. What am I doing wrong?
Solved! Go to Solution.
@olivere91 okay, so the concept of DATESYTD and TOTALYTD etc don't really work mid periods.
I've put together the following for you and tested it so it works. Probably not the best use of DAX but nonetheless will give you what you want:
Note that in the below, I've called my table "t" so please adjust accordingly. This measure also don't require a Date table. Just use the Date column from your Fact table.
CurYear =
VAR _CurYear = YEAR ( TODAY () )
VAR _CurMth = MONTH ( TODAY() )
VAR _CurDay = DAY ( TODAY () )
VAR _LastDay = DATE ( _CurYear , _CurMth , _CurDay )
VAR _FirstDay = DATE ( _CurYear , 1 , 1 )
VAR _Calc = CALCULATETABLE ( VALUES ( 't'[Date] ) , FILTER ( 't' , 't'[Date] >= _FirstDay && 't'[Date] <= _LastDay ) )
RETURN
CALCULATE ( SUM ( 't'[Amount] ) , FILTER ( 't' , 't'[Date] >= _FirstDay && 't'[Date] <= _LastDay ) )
For the last year measure, just simply add "-1" to the end of the _CurYear variable like below:
LstYear =
VAR _CurYear = YEAR ( TODAY () ) -1
VAR _CurMth = MONTH ( TODAY() )
VAR _CurDay = DAY ( TODAY () )
VAR _LastDay = DATE ( _CurYear , _CurMth , _CurDay )
VAR _FirstDay = DATE ( _CurYear , 1 , 1 )
VAR _Calc = CALCULATETABLE ( VALUES ( 't'[Date] ) , FILTER ( 't' , 't'[Date] >= _FirstDay && 't'[Date] <= _LastDay ) )
RETURN
CALCULATE ( SUM ( 't'[Amount] ) , FILTER ( 't' , 't'[Date] >= _FirstDay && 't'[Date] <= _LastDay ) )
Output for the above will look like:
Sorry I didn't get this for you the first time round.
Cheers,
Theo
If I have posted a response that resolves your question, please accept it as a solution to formally close the post.
Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!
Want to connect?www.linkedin.com/in/theoconias
Since you are sure about your measure, create a new table as below (for testing) and check the dates data
RETURN
CALCULATETABLE (
SAMEPERIODLASTYEAR ( 'Dates'[Date] ),
'Dates'[Date] = TODAY()
)
Hi @olivere91
Do you get the correct output if you adjust your measure to:
Total Sales YTD LY = CALCULATE ( [Total Sales YTD] , DATEADD ( 'Dates'[Date] , -1 , YEAR ) )
Hope this works.
Theo 🙂
If I have posted a response that resolves your question, please accept it as a solution to formally close the post.
Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!
Want to connect?www.linkedin.com/in/theoconias
Hey TheoC,
No, I get the same total as before, so a total through EOM Feb 2021.
@olivere91 no worries.
What are you running for the Current Year To Date measure? Is it:
Cur Yr to Date = TOTALYTD ( SUM ( 'Table'[Amount] ) , 'Date'[Date] )
or is it something else?
If I have posted a response that resolves your question, please accept it as a solution to formally close the post.
Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!
Want to connect?www.linkedin.com/in/theoconias
@olivere91 okay, so the concept of DATESYTD and TOTALYTD etc don't really work mid periods.
I've put together the following for you and tested it so it works. Probably not the best use of DAX but nonetheless will give you what you want:
Note that in the below, I've called my table "t" so please adjust accordingly. This measure also don't require a Date table. Just use the Date column from your Fact table.
CurYear =
VAR _CurYear = YEAR ( TODAY () )
VAR _CurMth = MONTH ( TODAY() )
VAR _CurDay = DAY ( TODAY () )
VAR _LastDay = DATE ( _CurYear , _CurMth , _CurDay )
VAR _FirstDay = DATE ( _CurYear , 1 , 1 )
VAR _Calc = CALCULATETABLE ( VALUES ( 't'[Date] ) , FILTER ( 't' , 't'[Date] >= _FirstDay && 't'[Date] <= _LastDay ) )
RETURN
CALCULATE ( SUM ( 't'[Amount] ) , FILTER ( 't' , 't'[Date] >= _FirstDay && 't'[Date] <= _LastDay ) )
For the last year measure, just simply add "-1" to the end of the _CurYear variable like below:
LstYear =
VAR _CurYear = YEAR ( TODAY () ) -1
VAR _CurMth = MONTH ( TODAY() )
VAR _CurDay = DAY ( TODAY () )
VAR _LastDay = DATE ( _CurYear , _CurMth , _CurDay )
VAR _FirstDay = DATE ( _CurYear , 1 , 1 )
VAR _Calc = CALCULATETABLE ( VALUES ( 't'[Date] ) , FILTER ( 't' , 't'[Date] >= _FirstDay && 't'[Date] <= _LastDay ) )
RETURN
CALCULATE ( SUM ( 't'[Amount] ) , FILTER ( 't' , 't'[Date] >= _FirstDay && 't'[Date] <= _LastDay ) )
Output for the above will look like:
Sorry I didn't get this for you the first time round.
Cheers,
Theo
If I have posted a response that resolves your question, please accept it as a solution to formally close the post.
Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!
Want to connect?www.linkedin.com/in/theoconias
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 35 | |
| 32 | |
| 25 | |
| 22 | |
| 18 |
| User | Count |
|---|---|
| 65 | |
| 35 | |
| 32 | |
| 25 | |
| 23 |