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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
atresadern
Regular Visitor

DAX command to get total sales for YTD in Direct mode

Hi 

 

I have a table with SalesAmount and SalesDate and want to be able to see the YTD total.  Our year runs from 1st May-30April.

This is the code I have but I keep getting syntax incorrect.

 

YTD Billing = CALCULATE(SUM(vw_PBI_Dashboard_Bills[BilledAmount]), DATESYTD(MIN(DATE(YEAR(vw_PBI_Dashboard_Bills[CreatedDate]), MONTH(vw_PBI_Dashboard_Bills[CreatedDate]), VALUE(TEXT(RIGHT(vw_PBI_Dashboard_Bills[CreatedDate], 2))))), "4/30"))
 
Thanks
Alison
1 ACCEPTED SOLUTION
johnt75
Super User
Super User

For the time intelligence functions to work correctly you need a proper date table, marked as a date table. Link the 'Date'[Date] column to your vw_PBI_Dashboard_Bills[CreatedDate] column and then the measure becomes simply

YTD Billing =
CALCULATE (
    SUM ( vw_PBI_Dashboard_Bills[BilledAmount] ),
    DATESYTD ( 'Date'[Date], "4/30" )
)

View solution in original post

6 REPLIES 6
atresadern
Regular Visitor

Thanks for your response, I appreciate your input.  I can get it working with a different calendar table which is limited to just the dates in our year but not the full date table which has 20 years of dates (I could probably reduce this).  

 

atresadern
Regular Visitor

I have a date table created from an article but it's not working when I use 

DATESYTD ( 'Date'[Date], "4/30" )

rather than the Created date.  I've linked the table and tried linking both ways but got blank results - any ideas?

 

Thanks

There needs to be some element from the date table in the visual. If there isn't, try adding a filter so that the date is in this day.

johnt75
Super User
Super User

For the time intelligence functions to work correctly you need a proper date table, marked as a date table. Link the 'Date'[Date] column to your vw_PBI_Dashboard_Bills[CreatedDate] column and then the measure becomes simply

YTD Billing =
CALCULATE (
    SUM ( vw_PBI_Dashboard_Bills[BilledAmount] ),
    DATESYTD ( 'Date'[Date], "4/30" )
)

Thanks, @johnt75 

This seems to work, rather than linking the date table, any reason why I shouldn't do it this way?

YTD Billing =
CALCULATE (
    SUM ( vw_PBI_Dashboard_Bills[BilledAmount] ),
    DATESYTD ('vw_PBI_Dashboard_Bills'[CreatedDate], "4/30" )
)

That might work but it is considered best practice to have a proper date table. As well as guaranteeing that the time intelligence functions work as expected you can break the data down by month, week etc and you can add other useful columns such as is the day a working day or not. There's lots of articles and videos on creating a date table.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors