cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TarifAlanazi
Helper I
Helper I

how to have current week and previse week

how to have current week and previse week

Current Month =
    var _currnetMonth = MONTH(MAX(Overall[Date]))
    var _currentYear = YEAR(MAX(Overall[Date]))
return
    CALCULATE(SUM(Overall[Hours]),
            MONTH('Date'[Date]) = _currnetMonth,
            YEAR('Date'[Date]) = _currentYear)
 
 
 
thanks 
1 ACCEPTED SOLUTION
FormerCognos
Frequent Visitor

Here's a really messy way of doing it that I'm sure someone will improve on:
/*calculated table*/
Current and Previous Week Hours = 
var _currentDate = Max('Date'[Date])
var _currentWkStart = DATEADD(_currentDate, -6, Day)
var _previousWkStart = DATEADD(_currentWkStart, -14, Day)
Return Summarize("CurrentWeekHours", sumx(Filter(AllSelected(Overall), [Date]>=_currentWkStart && [Date] <=_currentDate), [Hours])
, "PreviousWeekHours", sumx(Filter(AllSelected(Overall), [Date]<_currentWkStart && [Date] >=_previousWkStart), [Hours]))

Alternatively you could use the variables to create a flag (calculated column) in your date table to identify current and previous weeks 😆 
/*Calcuated Current Week Flag */ Return if(AND([Date] >=_currentWkStart, [Date] <=_currentDate), "Y", "N")
/*Calcuated Previous Week Flag */ Return if(AND([Date] >=_currentWkStart, [Date] <=_currentDate), "Y", "N")

View solution in original post

1 REPLY 1
FormerCognos
Frequent Visitor

Here's a really messy way of doing it that I'm sure someone will improve on:
/*calculated table*/
Current and Previous Week Hours = 
var _currentDate = Max('Date'[Date])
var _currentWkStart = DATEADD(_currentDate, -6, Day)
var _previousWkStart = DATEADD(_currentWkStart, -14, Day)
Return Summarize("CurrentWeekHours", sumx(Filter(AllSelected(Overall), [Date]>=_currentWkStart && [Date] <=_currentDate), [Hours])
, "PreviousWeekHours", sumx(Filter(AllSelected(Overall), [Date]<_currentWkStart && [Date] >=_previousWkStart), [Hours]))

Alternatively you could use the variables to create a flag (calculated column) in your date table to identify current and previous weeks 😆 
/*Calcuated Current Week Flag */ Return if(AND([Date] >=_currentWkStart, [Date] <=_currentDate), "Y", "N")
/*Calcuated Previous Week Flag */ Return if(AND([Date] >=_currentWkStart, [Date] <=_currentDate), "Y", "N")

Helpful resources

Announcements
Vote for T-Shirt Design

Power BI T-Shirt Design Challenge 2023

Vote for your favorite t-shirt design now through March 28.

March 2023 Update3

Power BI March 2023 Update

Find out more about the March 2023 update.

March Events 2023A

March 2023 Events

Find out more about the online and in person events happening in March!

Top Solution Authors