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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Dynamically Calculating Year-to-Date (YTD) Based on Selected Date Field in Power BI

I have two date fields: "Check Day" and "Work Day". I need a Year-to-Date (YTD) calculation that works dynamically for both fields. In Power BI, I can create metrics that work for individual date fields, but I'm trying to figure out a way to make the calculation dynamic for both date fields simultaneously.

Currently, I've managed to create separate calculations using TOTALYTD, like so:

TOTALYTD([Metric], 'MyDataSet'[Check Day].[Date])
TOTALYTD([Metric],
'MyDataSet'[Work Day].[Date])

However, I need to combine these into a single DAX calculation. When I select "Check Date" and YTD, it should calculate numbers based on the "Check Day" field. Similarly, when I select "Work Day", the calculation should be based on that date field.

How can I achieve this in DAX?

 

 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Got this as a solution for the problem, getting almost the desired output.

VAR MaxDate = MAX(DataSet[W_Date])
VAR MaxDate2 = MAX(DataSet[C_Date])
VAR YTDValue =
SWITCH(TRUE,
ISINSCOPE( DataSet[W_Date]),
CALCULATE(
[Burden],
FILTER(
ALL(DataSet[W_Date]),
(DataSet[W_Date] <= MaxDate && YEAR(DataSet[W_Date]) = YEAR(MaxDate) )
)),
ISINSCOPE( DataSet[C_Date]),
CALCULATE(
[Burden],
FILTER(
ALL(DataSet[C_Date]),
(DataSet[C_Date] <= MaxDate2 && YEAR(DataSet[C_Date]) = YEAR(MaxDate2) )
)),
TRUE,
BLANK() -- Handles case where neither date field is selected
)

RETURN
YTDValue

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Got this as a solution for the problem, getting almost the desired output.

VAR MaxDate = MAX(DataSet[W_Date])
VAR MaxDate2 = MAX(DataSet[C_Date])
VAR YTDValue =
SWITCH(TRUE,
ISINSCOPE( DataSet[W_Date]),
CALCULATE(
[Burden],
FILTER(
ALL(DataSet[W_Date]),
(DataSet[W_Date] <= MaxDate && YEAR(DataSet[W_Date]) = YEAR(MaxDate) )
)),
ISINSCOPE( DataSet[C_Date]),
CALCULATE(
[Burden],
FILTER(
ALL(DataSet[C_Date]),
(DataSet[C_Date] <= MaxDate2 && YEAR(DataSet[C_Date]) = YEAR(MaxDate2) )
)),
TRUE,
BLANK() -- Handles case where neither date field is selected
)

RETURN
YTDValue

samratpbi
Super User
Super User

You may try using Fields Parameter option. This is under Modeling -> New Parameter -> Fields. You can select which measures to choose. That will add a slicer in your report accordingly.

Anonymous
Not applicable

Doing this as part of creating a dataset for self service BI. We will be publishing just the dataset for the users and allowing them to create their own reports. So adding slicers or fields is not possible 

MNedix
Super User
Super User

Hi,

When you say date fields do you refer to columns in your dataset or individual measures?



If the post helped then please give it a Kudos and mark it as the solution so others can see it.
Cheers,
Anonymous
Not applicable

Columns from my dataset. There is a cube where I have all these date fields and metrics 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors