Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Last 6 months data

I need to display last 6 months from the fiscal month column ignoring the current month (data type is text-FY22JAN) .The fiscal month totally containing 18 months and i need to display only last six months. and also the date table is not the hirarchey one. how i need to write DAX expression for this. Please help me out anyone immediately.

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi, actually i have calendar date column . so i have solved this without writing any measure using PBI only. 

     

    i have dragged calendar date column in filters on page then , in last 6 month i have selected and then i selected calendar months means only completed months. so it will give only last six months of of fiscal month column even if the year changes later.

     

     

  • Hi Anonymous,

     

    That’s great! Thanks for your reply!

     

    Could you please mark the solution by Accept it as the solution to help other members find it more quickly. Thanks in advance!

     

    Best Regards,

    Community Support Team _ Caiyun

3 Replies

  • v-cazheng-msft's avatar
    v-cazheng-msft
    Community Support

    Hi Anonymous,

     

    Not sure how your model looks like. If you don’t have a calendar table, you may try this solution.

    Create a Measure as follows. It will help you filter out the last six months.

     

    LastSixMonths =
    VAR year_ =
        2000 + LEFT ( RIGHT ( MAX ( 'Fiscal Month'[fiscal month] ), 5 ), 2 )
    VAR month_ =
        RIGHT ( MAX ( 'Fiscal Month'[fiscal month] ), 3 )
    VAR month_no =
        SWITCH (
            month_,
            "Jan", 1,
            "Feb", 2,
            "Mar", 3,
            "Apr", 4,
            "May", 5,
            "Jun", 6,
            "Jul", 7,
            "Aug", 8,
            "Sep", 9,
            "Oct", 10,
            "Nov", 11,
            "Dec", 12
        )
    VAR fiscalDate =
        DATE ( year_, month_no, 1 )
    VAR firstDay =
        DATE ( year_, month_no, 1 )
    VAR currentTime =
        TODAY ()
    VAR currentYear =
        YEAR ( currentTime )
    VAR currentMonth =
        MONTH ( currentTime )
    VAR lastSixMonOfCur = 12 - ( 6 - currentMonth )
    VAR MinDate =
        IF (
            lastSixMonOfCur >= 6,
            DATE ( currentYear - 1, lastSixMonOfCur, 1 ),
            DATE ( currentYear, lastSixMonOfCur, 1 )
        )
    RETURN
        IF (
            fiscalDate >= MinDate
                && fiscalDate < DATE ( currentYear, currentMonth, 1 ),
            1,
            0
        )

     

     

    After that, you could calculated based on it or just filter visual data by dragging it to Filters pane.

     

    Also, attached the pbix file as reference.

     

    If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let me know. Thanks a lot!

     

    Best Regards,

    Community Support Team _ Caiyun

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi, actually i have calendar date column . so i have solved this without writing any measure using PBI only. 

       

      i have dragged calendar date column in filters on page then , in last 6 month i have selected and then i selected calendar months means only completed months. so it will give only last six months of of fiscal month column even if the year changes later.

       

       

      • v-cazheng-msft's avatar
        v-cazheng-msft
        Community Support

        Hi Anonymous,

         

        That’s great! Thanks for your reply!

         

        Could you please mark the solution by Accept it as the solution to help other members find it more quickly. Thanks in advance!

         

        Best Regards,

        Community Support Team _ Caiyun