Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

How to take To Date from Date range using Dax

Hi All,

 

I want to Pick To Date only  which I have highlight below using dax and As I am using Date ranges as well

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi,
    Try the following dax formula.

     

    Previous year = CALCULATE(SUM('Table'[Sales]), FILTER(ALL('Table'), 'Table'[Date] <= MAX('Table'[Date]) && 'Table'[Year] = YEAR(TODAY())))

     

    Best Regards,

    Wisdom Wu

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

8 Replies

  • rubayatyasmin's avatar
    rubayatyasmin
    Icon for Community Champion rankCommunity Champion

    Hi, Anonymous 

     

    You mean, you want to get the max date? 

     

    MAX(YourDateTable[Date]) - Should do the work

    • Anonymous's avatar
      Anonymous
      Not applicable

      If I select date  from date range which I have highlight (To Date) for example 3/31/2024 or 3/21/2024 and from Date if it select 1/31/2024 which is fixed will it show 3 months using Dax 

      • Ankur04's avatar
        Ankur04
        Icon for Resolver II rankResolver II

        Hi,

         

        It would be really helpful if you write your query property. it is not clear what you exactly want to achieve.

         

        Thanks,

         

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

    Based on my testing, please try the following methods:

    1.Create the sample table.

    2.Create the measure to get the To date and from date.

    To Date = MAX('Table'[Date])
    From Date = MIN('Table'[Date])

    3.Drag the measure into the card visual.

    Best Regards,

    Wisdom Wu

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

    • Anonymous's avatar
      Anonymous
      Not applicable

      Yes but how to calculate  Previous period and Previous Year sales from To Date selection. if you show me in the same pbi file 

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Anonymous ,

        Please try the following methods:

        1.Create the sample table.

        2.Create the new measure to calculate previous period and previous year.

        Previous year = CALCULATE(SUM('Table'[Sales]), FILTER(ALL('Table'), 'Table'[Year] = YEAR(MAX('Table'[Date])) - 1))
        Previous preiod = CALCULATE(SUM('Table'[Sales]), DATESBETWEEN('Table'[Date], MIN('Table'[Date]), MAX('Table'[Date])))

        3.Drag the measures into the card visual. Select the to date.

        Best Regards,

        Wisdom Wu

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