Forum Discussion

asebes's avatar
asebes
Frequent Visitor
5 years ago
Solved

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       
  • Anonymous's avatar
    Anonymous
    5 years ago

    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 )
            )
        )

    Best Regards

4 Replies

    • asebes's avatar
      asebes
      Frequent Visitor

      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!

  • Anonymous's avatar
    Anonymous
    Not applicable

    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 )
            )
        )

    Best Regards

    • asebes's avatar
      asebes
      Frequent Visitor

      works great! thanks for the expertise!