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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
pledington
Frequent Visitor

Year to date with slicer

Hi, I'm new to Power BI and hope someone can help me with a problem I have calculating a Year to Date value. I get the correct number sometimes but some dates I select in my slicer I get the wrong answer.

 

Our Financial year is 31st March, I'm trying to create a table that has our year to date sale number based on a date selection from a slicer, if I choose any date up to Jul-17 I'm getting the right answer but After that e.g. Aug-17 I get a smaller number than Jul-17, not bigger. I think it's because of the filter on the slicer and tried to use the All function but it doesn't like it.

 

My slicer is based on the table/column called 'Sales Master' [RRD] that is in date format on the query.

 

I have over 4 years of sales data and want to be able to get the YTD number based on any date selection e.g. if the slicer is Jul 17 then it's from Apr-17 to Jul-17, if I select Feb-17 then i want from Apr-16 to Feb-17.

 

I created a new measure with the following :

 

USD.YTD = calculate(sum('Sales Master'[USD.A]);
   DATESBETWEEN('Sales Master'[RRD];
    DATE(IF(MONTH(LASTDATE(DATEADD('Sales Master'[RRD];0;MONTH)))>3;
     YEAR(LASTDATE(DATEADD('Sales Master'[RRD];0;MONTH)));
     YEAR(LASTDATE(DATEADD('Sales Master'[RRD];0;MONTH)))-1);4;1);
    LASTDATE(DATEADD('Sales Master'[RRD];0;MONTH))
  ))

 

Not sure if I just need to/possible to change the 2nd line above to something like: DATESBETWEEN(ALL('Sales Master'[RRD]); or a more simple approach to this?

 

I also know I need to do some error handling on this e.g. if the slicer has no selection it returns something funny rather than the entire total.

 

Any help pointing me in the right direction is much appreciated

 

Thanks

1 REPLY 1
v-huizhn-msft
Microsoft Employee
Microsoft Employee

Hi @pledington,

Your date filed in resource table is continuous or not? If not, you should create a calendar table, relate the calendar table to 'Sales Master' table by [date] field. Then you can try the fomula below.


USD.YTD =
IF (
    MONTH ( LASTDATE ( DATEADD ( 'Sales Master'[RRD], 0, MONTH ) ) ) > 3,
    CALCULATE (
        TOTALYTD ( 'Sales Master'[RRD], 'Calendar'[DATE] ),
        DATEADD ( 'Calendar'[Date], -3, MONTH )
    ),
    CALCULATE (
        TOTALYTD ( 'Sales Master'[RRD], 'Calendar'[DATE] ),
        SAMEPERIODLASTYEAR ( Calendar[Date] )
    )
)


If this still returns uncorrect result, could you please share your sample table for further analysis?

Best Regards,
Angelia

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

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

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.