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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
bipowerbix
Helper I
Helper I

YTD MEASURE NOT WORKING AS INTENDED

Here is the Table named test:

bipowerbix_0-1681163714430.png

 

Here is the table 2 which contains Dates, which is used as Slicer:

 

Dates = CALENDAR(date(2022,1,1),TODAY())

 

 

Link between Dates and test dataset:

bipowerbix_4-1681164544969.png

 

 

Question: Create a Measure that shows the YTD Total amount for the current year, even if the date slicer starts from the previous year:

 

Here is my code:

 

YTD = 
VAR minim = CALCULATE( MIN( Dates[Date]), ALLSELECTED(Dates[Date]))
var startyear = DATE(YEAR(TODAY()),1,1)
return if( minim >= startyear , 
calculate(sum(test[Totals] ), FILTER(Dates, Dates[Date] >= startyear))  ,  
 calculate(sum(test[Totals] ), FILTER(Dates, Dates[Date] >= startyear)) )

 

 

Test Scenario 1 Works fine:  Shows correct info, the date slicer starts at 2022, and the measure shows the YTD result of current year

bipowerbix_1-1681163883970.png

 

Test Scenario 2: Does Not Work, Shows 40 instead of 130 (Expected output 130)

bipowerbix_2-1681163965165.png

 

Test Scenario 3: Does not work, Even when the year is the current year, (Expected output 130)

bipowerbix_3-1681164393279.png

 

 

 

 

1 ACCEPTED SOLUTION
PawarNovil
Resolver I
Resolver I

 

Hi @bipowerbix 

 

I got the desired result, please try the below measure.

-------------------------------------------------------

 

YTD =
VAR minim = CALCULATE( MIN( Dates[Date]), ALLSELECTED(Dates[Date])) //12-10-2022
var startyear = DATE(YEAR(TODAY()),1,1) // current start year date 1-1-2023
var a= if( minim >= startyear ,
calculate(sum(test[Totals] ), FILTER(all(Dates), Dates[Date] >= startyear))  ,  
 calculate(sum(test[Totals] ), FILTER(all(Dates), Dates[Date] >= startyear))
 
  )
 return a

-------------------------------------------------

 

PawarNovil_0-1681223430434.pngPawarNovil_1-1681223696969.png

--------------------------------------------------------------------------

Regards,

Novil

If I answer your question, please mark my post as a solution.

 

 

 

View solution in original post

9 REPLIES 9
bipowerbix
Helper I
Helper I

Nice man, I will use this in future cases

PawarNovil
Resolver I
Resolver I

 

Hi @bipowerbix 

 

I got the desired result, please try the below measure.

-------------------------------------------------------

 

YTD =
VAR minim = CALCULATE( MIN( Dates[Date]), ALLSELECTED(Dates[Date])) //12-10-2022
var startyear = DATE(YEAR(TODAY()),1,1) // current start year date 1-1-2023
var a= if( minim >= startyear ,
calculate(sum(test[Totals] ), FILTER(all(Dates), Dates[Date] >= startyear))  ,  
 calculate(sum(test[Totals] ), FILTER(all(Dates), Dates[Date] >= startyear))
 
  )
 return a

-------------------------------------------------

 

PawarNovil_0-1681223430434.pngPawarNovil_1-1681223696969.png

--------------------------------------------------------------------------

Regards,

Novil

If I answer your question, please mark my post as a solution.

 

 

 

FreemanZ
Super User
Super User

hi @bipowerbix 

what is your expected result for scenario 2  and 3?

Hi FreemanZ,

 

The expected output for all test scenarios should be 130, that is the YTD total for the current year.

hi @

why YTD in scenario 2 and 3 are 130?

That's what we want to achieve, For 2023, We have 3 records, 40,80, and 10, which adds up to 130. Need to show 130 in card visual using DAX measure, 

try like:

Measure = 
SUMX(
    FILTER(
        ALL(test),
        test[date]=YEAR(MAX(dates[date]))
            && test[date]<=TODAY()
    )
    test[Totals]
)

Doesn't Work, Gives output as blank. (Image below of Visual titled Measure)

bipowerbix_0-1681192865963.png

 

hi @bipowerbix 

there is a typo, try like:

Measure =
SUMX(
    FILTER(
        ALL(test),
        YEAR(test[date])=YEAR(MAX(dates[date]))
            && test[date]<=TODAY()
    ),
    test[Totals]
)

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.