Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
olivere91
Helper I
Helper I

YTD LY Returning full month

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?

 

Total Sales YTD LY =
CALCULATE(Item_Sales_Profit[Total Sales YTD],SAMEPERIODLASTYEAR(Dates[Date]))
1 ACCEPTED 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:

TheoC_1-1644280174713.png

 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

View solution in original post

6 REPLIES 6
sevenhills
Super User
Super User

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() 
    )

 

 

 

TheoC
Super User
Super User

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

@TheoC 

 

Total Sales YTD = TOTALYTD(Item_Sales_Profit[Total Revenue],Dates[Date])
 
Total Revenue = SUM(Item_Sales_Profit[Revenue])

@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:

TheoC_1-1644280174713.png

 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

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.