Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext 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
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
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 48 | |
| 43 | |
| 39 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 69 | |
| 63 | |
| 32 | |
| 30 | |
| 23 |