Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
The Report has a Sales table with Date, Product, Amount$ fields, also have two filters, Date and Product matching the same name fields.
The financial year end date is 31 March.
How to write a measure to calculate the year-to-date total amount$ based on the current two filters?
For example:
Case 1
If the user selected Date filter range from 2020-09-01 to 2020-07-14,
then the year-to-date total amount$ will be from 2020-04-01 to 2020-07-14.
Case 2
If the user selected Date filter range from 2020-02-01 to 2020-08-31, with Product filter Product01 selected
then the year-to-date total amount$ will be from 2019-04-01 to 2020-08-31 for Product01.
Notes: in case 2, since the user selected Date filter range covers two financial years, so the year-to-date should also cover two financial years from 2019-04-01 to the max date of the user selected date range 2020-08-31.
Solved! Go to Solution.
Hi @j_w ,
We can create a FY date table that has now relationship with the Sales table and a measure to meet your requirement.
1. Create a date table and add two columns.
Date table = CALENDARAUTO()
FY =
var _FY = if(month([Date])<=3,year([Date])-1,year([Date]))
return
_FY
Star FY = DATE('Date table'[FY],4,1)
2. Then we can create a measure and use the Date table [Date] to be a slicer.
Measure =
VAR _min_date =
MIN ( 'Date table'[Date] )
VAR _max_date =
MAX ( 'Date table'[Date] )
VAR _currentFYmonth =
CALCULATE (
MAX ( 'Date table'[Star FY] ),
FILTER ( 'Date table', 'Date table'[Date] = _min_date )
)
VAR _result_date =
IF (
_min_date > _currentFYmonth,
_currentFYmonth,
DATE ( YEAR ( _currentFYmonth ) - 1, MONTH ( _currentFYmonth ), 1 )
)
RETURN
CALCULATE (
SUM ( 'Table'[amount] ),
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Date] >= _result_date
&& 'Table'[Date] <= _max_date
)
)
If it doesn’t meet your requirement, could you please show the exact expected result based on the table that we have shared?
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
BTW, pbix as attached.
Hi @j_w ,
We can create a FY date table that has now relationship with the Sales table and a measure to meet your requirement.
1. Create a date table and add two columns.
Date table = CALENDARAUTO()
FY =
var _FY = if(month([Date])<=3,year([Date])-1,year([Date]))
return
_FY
Star FY = DATE('Date table'[FY],4,1)
2. Then we can create a measure and use the Date table [Date] to be a slicer.
Measure =
VAR _min_date =
MIN ( 'Date table'[Date] )
VAR _max_date =
MAX ( 'Date table'[Date] )
VAR _currentFYmonth =
CALCULATE (
MAX ( 'Date table'[Star FY] ),
FILTER ( 'Date table', 'Date table'[Date] = _min_date )
)
VAR _result_date =
IF (
_min_date > _currentFYmonth,
_currentFYmonth,
DATE ( YEAR ( _currentFYmonth ) - 1, MONTH ( _currentFYmonth ), 1 )
)
RETURN
CALCULATE (
SUM ( 'Table'[amount] ),
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Date] >= _result_date
&& 'Table'[Date] <= _max_date
)
)
If it doesn’t meet your requirement, could you please show the exact expected result based on the table that we have shared?
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
BTW, pbix as attached.
@j_w ,
You can use start of year with end date of year given in function. Or you can start of year from you table . Use date table as you need Continuous dates for this
Measure =
var _min = minx(allselected(Date),startofyear([Date[Date],"3/31")) //or use start of year from calendar
var _max = maxx(allselected(Date),[Date[Date])
return
calculate([measure], filter(all(Date), Date[DAte]<=_max && Date[DAte]>=_min))
FY of your choice - https://community.powerbi.com/t5/Community-Blog/Creating-Financial-Calendar-Decoding-Date-and-Calend...
@j_w ,
Try like
Measure =
var _min = minx(allselected(Date),startofyear([Date[Date],"3/31")) // take start of year from you date table
var _max = maxx(allselected(Date),[Date[Date])
return
calculate([measure], filter(all(Date), Date[DAte]<=_max && Date[DAte]>=_min))
Make sure you use a date table with continuous date
Hi, @j_w , you can assign a specific date as year_end_date in TOTALYTD func, say "3/31" for your case,
TOTALYTD(<expression>,<dates>[,<filter>][,<year_end_date>])
Official doc for more details,
https://docs.microsoft.com/en-us/dax/totalytd-function-dax
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
@AllisonKennedy I have added some explanation:
In case 2, since the user selected Date filter range covers two financial years, so the year-to-date should also cover two financial years from 2019-04-01 to the max date of the user selected date range 2020-08-31.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
118 | |
84 | |
49 | |
38 | |
28 |
User | Count |
---|---|
185 | |
73 | |
73 | |
50 | |
42 |