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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Akshay123
Helper I
Helper I

Need to Show last 7 days data on Total YTD calculation

Hello Experts,

 

I have used below logic to find Total YTD values. When I used it in a visual I see no's for entire year. I just want to show the last 7 days of the values in the graph.

When I use relative day option under filter pane, It filters data for last 7 days and calculates and gives the result.

 

TotalYTDMeasure = TOTALYTD([Total New Open], Cal[Date].[Date])
 
Akshay123_0-1715792277539.png

 

2 REPLIES 2
v-nuoc-msft
Community Support
Community Support

Hi @Akshay123 

 

If you are not getting the total calculated data for the last seven days correctly, it may have something to do with the function you are using.

 

TOTALYTD is intended to represent an expression calculated for the current year-to-date date.

 

Therefore, the function will start counting from the beginning of the current year, regardless of the filter criteria you have in the filter pane.

 

For your question, here is the method I provided:

 

Here's some dummy data

 

“Table”

vnuocmsft_2-1715824836513.png

 

Here I recommend you to modify the code as follows, create a measure:

 

Measure = 
var _lastdate = MAX('Table'[year])
var _startdate = _lastdate - 7
RETURN
CALCULATE(
    SUM('Table'[values]), 
    FILTER(
        ALL('Table'), 
        'Table'[year] >= _startdate && 'Table'[year] <= _lastdate
    )
)

 

Here is the result.

 

vnuocmsft_1-1715824774731.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

HI @v-nuoc-msft 

When I am using date column within the table, above solution it works, 

In my report I used a calander table to show the dates, for blank dates it's not showing the values

for blanks it has to show the previous values

 

Akshay123_0-1715850203124.png

 

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!