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
Namoh
Post Partisan
Post Partisan

Adding WHERE MAX statement into DAX measure TOTALYTD

Hi.

 

I’ve got a DAX measure which calculates the TOTALYTD: YTD_Unplanned_Downtine_Target = IF( SUM(Targets[Target Unplanned downtime (hrs)]) = BLANK(); BLANK ();TOTALYTD(SUM(Targets[Target Unplanned downtime (hrs)]);'CALENDAR'[Date];ALL('CALENDAR');"3/31"))

 

This works fine. But when I put this in a table it will show all figures for the whole year, see picture 1.

TOTALYTD.png

 

I would like to only show the results uptill the current month, so I can compare the targets with the actuals, without having to use/change the filter each month.

 

I’ve made a measure which looks up the latest month, see picture 2: Latest Month = MAX(kpiexport[Month])

Latest_Month.png 

 

How to merge both measures into one measure so that the TOTALYTD, for the future months, wont show in my table?

I assume I have to combine the MAX with somekind of WHERE statement?

If another method is possible, I’m also interested in hearing this.

 

1 ACCEPTED SOLUTION

Ok, so to be honest, I don't know what I did to make it work, but it works!

 

I was fooling around with some fields (Calendar-Date vs Targets-Begin van de maand), I was adding a Filter onto measure _5_ stating show all that's Not Empty, I clicked in the table in the right top corner on Zoom Out and Expand 1 level in Hierarchie, etc and now it shows:

1. just the values of the beginning of the months

2. it summarizes after each month

3. it stops after the current month

 

Thanks for your help.

 

It_works.png

 

 

 

View solution in original post

26 REPLIES 26

Yes, you can choose add measure and below is add column, which I thought was the same as adding a measure but then as column so you could see directly the outcome. But I'm a newbie regarding power bi so I could have made a wrong assumption.

 

So I've created 2 columns via add column in DAX, the option below add measure.

@Namoh  Try to create the report like this:

1.PNG

Well I've created the measures instead as columns and now I don't get an error?

 

Someone must explain to me what the difference is between these two options, because I expected the same outcome (with the same formula) but apparently with the column option I get an error but with the measure option it works fine...?

 

So I've created the report but it's not taking into account the FY, starting at april nor does it not show the future months.......

 

I'm still at the same level as my original post.

 

SUM_No_YTD.png

Thanks, this gives a bit more insight.

 

Anyone who can help me with my original issue, still not working as expected.

amitchandak
Super User
Super User

@Namoh ,  refer if these can help

example

YTD QTY forced= 
var _max = today()
return
calculate(Sum('order'[Qty]),DATESYTD('Date'[Date]),'Date'[Date]<=_max)
//calculate(TOTALYTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))

LYTD QTY forced= 
var _max = date(year(today())-1,month(today()),day(today()))
return
CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)


YTD QTY forced= 
var _max = maxx('order',[Order date])
return
calculate(Sum('order'[Qty]),DATESYTD('Date'[Date]),'Date'[Date]<=_max)
//calculate(TOTALYTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))

LYTD QTY forced= 
var _max1 =maxx('order',[Order date])
var _max = date(year(_max1)-1,month(_max1),day(_max1))
return
CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

 

use date table

https://www.youtube.com/watch?v=Qt0TM-4H09U&list=PLPaNVDMhUXGaaqV92SBD5X2hk3TMNlHhb&index=5

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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 Kudoed Authors