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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
Lukasz004
Frequent Visitor

TOTALYTD (Stop for specific month)

Dear all,

I´m trying a "simple" measure to calculate the cumulative values from the beginning of the year until a month from the most recent date.

For example, In FactSales table I have column OrderDate where the last date is 2020.07.30

The formula below works:

 

Sum Of Sales Amount YTD = 
VAR max_month = 7
RETURN
TOTALYTD(
    [Sum Of SalesAmount],
    DimDate[Date],
    MONTH(FactSales[OrderDate]) <= max_month 
)

 

but this formula does not work:

 

Sum Of Sales Amount YTD = 
VAR max_month = MONTH(MAX(FactSales[OrderDate]))
RETURN
TOTALYTD(
    [Sum Of SalesAmount],
    DimDate[Date],
    MONTH(FactSales[OrderDate]) <= max_month 
)

 

 

Any help?

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Lukasz004 , You have try like example

 

YTD=
var _max = maxx(allselected('order'),'order'[order date])
var _min = date(year(_max ),1,1)

return
CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Date] >=_min && 'Date'[Date] <= _max) )

 

or

 

YTD=
var _max = maxx(allselected('order'),'order'[order date])
var _min = date(year(_max ),1,1)

return
CALCULATE(sum('order'[Qty]), FILTER(('Date'),'Date'[Date] >=_min && 'Date'[Date] <= _max) )

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Lukasz004 , You have try like example

 

YTD=
var _max = maxx(allselected('order'),'order'[order date])
var _min = date(year(_max ),1,1)

return
CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Date] >=_min && 'Date'[Date] <= _max) )

 

or

 

YTD=
var _max = maxx(allselected('order'),'order'[order date])
var _min = date(year(_max ),1,1)

return
CALCULATE(sum('order'[Qty]), FILTER(('Date'),'Date'[Date] >=_min && 'Date'[Date] <= _max) )

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

I changed my variable:

VAR max_month = MONTH(MAX(FactSales[OrderDate]))

to

VAR max_month = MONTH(MAXX(ALL(FactSales), FactSales[OrderDate]))

 

and the formula works fine 😉

 

Thanks for your help @amitchandak 

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors