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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
AnandRanga
Helper III
Helper III

how to get top two months from a date column as filter ?

I am having a date field in which I have all the dates. I want to get only current month and previous month name as filter. How to do this ? 

I have tried max but it returns only current month number. Will TopN will work here, If yes can anyone tell me how?

Thanks for your time.

 

1 ACCEPTED SOLUTION

Hi @AnandRanga,

 

To remove the records in which MonthsNEW is blank, you can create a calculate table:

Table =
    CALCULATETABLE ( TIMESHEETANALYSISCUBE, TIMESHEETANALYSISCUBE[MonthsNEW] <> BLANK () )

 

Thanks,
Yuliana Gu

Community Support Team _ Yuliana Gu
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

3 REPLIES 3
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @AnandRanga,

 

You want to filter data, right? Please try the below formula to create a calculate table:

 

NewTable =
CALCULATETABLE (
    TopTwoMonth,
    FILTER (
        TopTwoMonth,
        TopTwoMonth[Date].[MonthNo] = MONTH ( TODAY () )
            || TopTwoMonth[Date].[Year]
                = IF (
                    MONTH ( TODAY () ) = 1,
                    YEAR ( TODAY () ) - 1,
                    YEAR ( TODAY () )
                        && TopTwoMonth[Date].[MonthNo]
                            = IF ( MONTH ( TODAY () ) = 1, 12, MONTH ( TODAY () ) - 1 )
                )
    )
)

If you have any question, please feel free to ask.

 

Thanks,
Yuliana Gu

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

I will try your solution  and will let you know baut for now I tried this and it is showing current and  previous month but It is showing (blank) also. Transdate is the column contains all the dates.

 

MonthsNEW = IF(MONTH(TIMESHEETANALYSISCUBE[TRANSDATE])=Month(NOW()), "Current Month",IF(MONTH(TIMESHEETANALYSISCUBE[TRANSDATE])=Month(NOW())-1,"Previous month")) 

 

Actually it is showing current and previous month but except these two months all the months are coming into (blank).

Is there any way to remove it ?

Thanks for your time.

Hi @AnandRanga,

 

To remove the records in which MonthsNEW is blank, you can create a calculate table:

Table =
    CALCULATETABLE ( TIMESHEETANALYSISCUBE, TIMESHEETANALYSISCUBE[MonthsNEW] <> BLANK () )

 

Thanks,
Yuliana Gu

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.