Forum Discussion

Nerdywantocode's avatar
2 years ago
Solved

Automatically filter month based on real date

Hi guys, I'm currently an finance officer and on of my monthly task is to create a PBI dashboard to present data of company. I want to automate my report so that once I have new data, I just have to ...
  • jdbuchanan71's avatar
    2 years ago

    Nerdywantocode 

    You should be able to do it just using the dates without adding the month to the table like this.

    Data_report = 
    VAR _Start = EOMONTH(TODAY(),-2)+1
    VAR _End = EOMONTH(TODAY(),0)
    RETURN 
    FILTER ( Data, Data[Date] >= _Start && Data[Date] <= _End )
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Nerdywantocode ,

    Here some steps that I want to share, you can check them if they suitable for your requirement.

    Here is my test data:

    1.Create a new calculated column in  `Data` table to determine the year and month combination for each transaction date.

     

    YearMonth = YEAR(Data[Date]) * 100 + MONTH(Data[Date])

     

    2.Create a measure.

    Two months ago = IF(
        MONTH(TODAY()) = 1 || 2,
        (YEAR(TODAY()) - 1) * 100 + 11,
        YEAR(TODAY()) * 100 + MONTH(TODAY()) - 2
    )

     

     

    3.Create another measure to calculate the  year and last month combination.

     

    LastMonth = IF(
        MONTH(TODAY()) = 1 || 2,
        (YEAR(TODAY()) - 1) * 100 + 12,
        YEAR(TODAY()) * 100 + MONTH(TODAY()) - 1
    )

     

    4.Create a calculate table to show the final output

     

    Table = CALCULATETABLE(Data,
        FILTER(
        Data,
        Data[YearMonth] = [Two months ago] || Data[YearMonth] = [LastMonth])
    )

     

    5.Final output

     

    Best regards

    Albert He

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