Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

YTD & MTD

Hello everyone,
I have Year slicer and month slicer as below in my report (kept single selection option in both)

i have added two buttons as below in my report for MTD & YTD

i have sales columns and date column on which sales occured
I have to create a measure when month is selected then it has to show MTD for selected month and when year is selected it has to show YTD till selected month.

 

Regards 

 

  • Hey Anonymous ,

     

    this article covers almost everything related to date/time calculations: Time patterns – DAX Patterns

    My advice would be to create two measures, one that calculates the MTD value and the 2nd one for the YTD.
    Instead of using buttons I would use an unrelated table 'mtd_ytd' that contains only one column [mtd_ytd] two values like "MTD" and "YTD".

    Then you can create a measure that might look like this:

    measure = 
    var selectedMTD_YTD = SELECTEDVALUE( 'MTD_YTD'[MTD_YTD] , "MTD")
    return
    IF (
    selectedMTD_YTD = "MTD"
    , [mtd measure]
    , [ytd measure]
    )

    Hopefully, this provides what you are looking for.

     

    Regards,

    Tom

  • Hi Anonymous ,

    According to your description, here's my solution.

    1.Create two measures for the MTD and YTD button.

    MTD Button = IF(ISFILTERED('Table'[Month]),"","MTD")
    YTD Button = IF(ISFILTERED('Table'[Year]),"","YTD")

    In the Format button pane>Style>Text, select the fx button, and apply the above measures.

    2.Create two measures for MTD and YTD.

    MTD =
    IF (
        ISFILTERED ( 'Table'[Month] ),
        TOTALMTD ( SUM ( 'Table'[Sales] ), 'Table'[Date] ),
        ""
    )
    
    YTD =
    IF (
        ISFILTERED ( 'Table'[Year] ),
        TOTALYTD ( SUM ( 'Table'[Sales] ), 'Table'[Date] ),
        ""
    )
    

    Put these two measures in two card visuals. 

    3.Put the MTD button on top of the MTD card visual, put the YTD button on top of the YTD card visual. Get the correct result.

    I attach my sample below for reference.

     

    Best Regards,
    Community Support Team _ kalyj

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

2 Replies

  • Hey Anonymous ,

     

    this article covers almost everything related to date/time calculations: Time patterns – DAX Patterns

    My advice would be to create two measures, one that calculates the MTD value and the 2nd one for the YTD.
    Instead of using buttons I would use an unrelated table 'mtd_ytd' that contains only one column [mtd_ytd] two values like "MTD" and "YTD".

    Then you can create a measure that might look like this:

    measure = 
    var selectedMTD_YTD = SELECTEDVALUE( 'MTD_YTD'[MTD_YTD] , "MTD")
    return
    IF (
    selectedMTD_YTD = "MTD"
    , [mtd measure]
    , [ytd measure]
    )

    Hopefully, this provides what you are looking for.

     

    Regards,

    Tom

  • Hi Anonymous ,

    According to your description, here's my solution.

    1.Create two measures for the MTD and YTD button.

    MTD Button = IF(ISFILTERED('Table'[Month]),"","MTD")
    YTD Button = IF(ISFILTERED('Table'[Year]),"","YTD")

    In the Format button pane>Style>Text, select the fx button, and apply the above measures.

    2.Create two measures for MTD and YTD.

    MTD =
    IF (
        ISFILTERED ( 'Table'[Month] ),
        TOTALMTD ( SUM ( 'Table'[Sales] ), 'Table'[Date] ),
        ""
    )
    
    YTD =
    IF (
        ISFILTERED ( 'Table'[Year] ),
        TOTALYTD ( SUM ( 'Table'[Sales] ), 'Table'[Date] ),
        ""
    )
    

    Put these two measures in two card visuals. 

    3.Put the MTD button on top of the MTD card visual, put the YTD button on top of the YTD card visual. Get the correct result.

    I attach my sample below for reference.

     

    Best Regards,
    Community Support Team _ kalyj

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