Forum Discussion

bettysmile's avatar
bettysmile
Regular Visitor
3 years ago

calculate Date filter SAMEPERIODLASTYEAR

Hello,

 

i have a calculate Date filter like this:

VAR Last month =   SELECTCOLUMNS(ADDCOLUMNS( CALCULATETABLE(
                    'Datum (D)', FILTER(ALLNOBLANKROW('Datum (D)'[Datum]), YEAR('Datum (D)'[Datum]) = YEAR(TODAY()) &&    MONTH('Datum (D)'[Datum])+1 = MONTH(TODAY())
                    )        ),  "Datebe","Last month"
            ), "Datebe",[Datebe], "Datum",'Datum (D)'[Datum], "Sort",21   )    
 
i have this filter for "last week", "last month", "last fincal year" (not calendar year).
 
Now i want to combine it with the function SAMEPERIODLASTYEAR:
 
CALCULATE(
    SUM('ABC)'[hourspertime]),  
    SAMEPERIODLASTYEAR(Datebe[Datum])          
)
 
but it doesn't work - have you an idea why?
Thank you

1 Reply

  • KVRKarthik's avatar
    KVRKarthik
    Frequent Visitor

    Hi,

    In the variable "Last Month", the table calculation is

    CALCULATETABLE(
                        'Datum (D)', FILTER(ALLNOBLANKROW('Datum (D)'[Datum]), YEAR('Datum (D)'[Datum]) = YEAR(TODAY()) &&    MONTH('Datum (D)'[Datum])+1 = MONTH(TODAY())
     
    As per this function, if MONTH(TODAY()) = "August" and YEAR(TODAY()) = 2023 then the Datebe[Datum] will have dates of 2023 and July Month.
    When the calculation is limited to current year and current year's previous month then this table cannot support you to navigate to same period last year.
    If you need to execute SAMEPERIODLASTYEAR in your presentation then please revise your filtering conditions in a new measure as  
    YEAR('Datum (D)'[Datum]) = YEAR(TODAY()) - 1 &&    MONTH('Datum (D)'[Datum])+1 = MONTH(TODAY())
    Hope this helps in resolving your issue.
    Regards,
    Karthik.
     
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.