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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
asebes
Frequent Visitor

YTD Context in Matrix

Seems like this should be easy but can't quite get my DAX Measure to work.  All I need is a YTD row in my matrix based on the applicable month.

 

So my matrix shows the previous 6 months and need a YTD number based on column header.  For example:

YTD Oct-20 would by Jan-20 through Oct-20

YTD Dec-20 would be Jan-20 through Dec-20

YTD Jan-21 would be Jan-21 through Jan-21

YTD Mar-21 would be Jan-21 through Mar-20

 

data Desired Output
datedata Oct-20Nov-20Dec-20Jan-21Feb-21Mar-21
Jan-205 29034139659122189
Jan-206       
Feb-207       
Feb-208       
Mar-209       
Mar-2010       
Apr-2011       
Apr-2012       
May-2013       
May-2014       
Jun-2015       
Jun-2016       
Jul-2017       
Jul-2018       
Aug-2019       
Aug-2020       
Sep-2021       
Sep-2022       
Oct-2023       
Oct-2024       
Nov-2025       
Nov-2026       
Dec-2027       
Dec-2028       
Jan-2129       
Jan-2130       
Feb-2131       
Feb-2132       
Mar-2133       
Mar-2134       
Apr-2135       
Apr-2136       
May-2137       
May-2138       
1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @asebes ,

You can create a measure as below and apply a relative date slicer, please find the details in the attachment.

Measure = 
VAR _curdate =
    SELECTEDVALUE ( 'Table'[date] )
RETURN
    CALCULATE (
        SUM ( 'Table'[data] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[date] >= DATE ( YEAR ( _curdate ), 1, 1 )
                && 'Table'[date] <= EOMONTH ( _curdate, 0 )
        )
    )

yingyinr_1-1617006042439.png

Best Regards

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

View solution in original post

4 REPLIES 4
v-yiruan-msft
Community Support
Community Support

Hi @asebes ,

You can create a measure as below and apply a relative date slicer, please find the details in the attachment.

Measure = 
VAR _curdate =
    SELECTEDVALUE ( 'Table'[date] )
RETURN
    CALCULATE (
        SUM ( 'Table'[data] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[date] >= DATE ( YEAR ( _curdate ), 1, 1 )
                && 'Table'[date] <= EOMONTH ( _curdate, 0 )
        )
    )

yingyinr_1-1617006042439.png

Best Regards

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

works great! thanks for the expertise!

amitchandak
Super User
Super User

@asebes , For YTD you can use measure like this with date table

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))

 

Now for 6 months the best that you use a relative date filter. https://docs.microsoft.com/en-us/power-bi/visuals/desktop-slicer-filter-date-range

 

 

 

Or use an independent date table to select date range : https://www.youtube.com/watch?v=duMSovyosXE

But won't that measure be filtered on the month's in the column header and only give me that month's respective data?

 

What I need, for example, if the header month is Dec-20 then I need a sum of the transactions from 1/1/20 through 12/31/20.  If the header is Feb-21, then would need a sum of the transactions from 1/1/21 through 2/28/21.

 

Hope that makes sense, thanks!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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