Forum Discussion
Calculating Previous Values
Last 2 Weeks new =
- Anonymous4 years ago
Would something like this serve? I am assuming that the source data has a [Fiscal Week Ends] column, not a hire date.
Last 2 Weeks New =
var currentweek = [Fiscal Week Num]var previousweek = [Fiscal Week Num]-1
var currentweekhires =
CALCULATE(
SUM(
'Terms & Hires SQL'[Net Hires]),
[Fiscal Week End]=currentweekvar previousweekhires =
CALCULATE(
SUM(
'Terms & Hires SQL'[Net Hires]),
[Fiscal Week End]=previousweekreturn
currentweekhires+previousweekhires
14 Replies
- TheoCCommunity Champion
Anonymous Could you please provide the output you want from your measure as it may not be clear exactly what you are trying to achieve? What is the output you want for the Last 2 Weeks New column in your image?
Thanks heaps,
Theo
- AnonymousNot applicable
A sum of net hires for the past two weeks and it should be rolling...
Starting at fiscal week 48
Fiscal week 49 = sum of net hires for week 48
Fiscal week 50 = sum of net hires for week 49 and 48
Fiscal week 51 = sum of net hires for week 49 and 50
Fiscal week 52 = sum of net hires for week 50 and 51
And so on
Fiscal week end date should be used as an identifier since it contains an actual dateDataset contains other columns that will be used as filters, location for example, so the values in the measure should change with the filters.
- TheoCCommunity Champion
Hi Anonymous,
You can use the following and adapt it your tables / column names:
14 Days =
VAR _1 = LASTDATE ( 'Table'[Date] ) // This is the date in your fact table
VAR _2 = _1 - 14 // represents the 14 days in the respective fortnight
RETURN
CALCULATE ( SUM ('Table'[Amount] ) , FILTER ( ALL ( 'Date') , AND ( 'Date'[Date] > _2 , 'Date'[Date] <= _1 ) ) )The above assumes you have a Date / Calendar table. If not, please adjust the 'Date' to the respective date column in your fact table.
Hope this helps 🙂
Theo
- AnonymousNot applicable
Would something like this serve? I am assuming that the source data has a [Fiscal Week Ends] column, not a hire date.
Last 2 Weeks New =
var currentweek = [Fiscal Week Num]var previousweek = [Fiscal Week Num]-1
var currentweekhires =
CALCULATE(
SUM(
'Terms & Hires SQL'[Net Hires]),
[Fiscal Week End]=currentweekvar previousweekhires =
CALCULATE(
SUM(
'Terms & Hires SQL'[Net Hires]),
[Fiscal Week End]=previousweekreturn
currentweekhires+previousweekhires
- AnonymousNot applicable
That didn't work even when I found the columns....
- AnonymousNot applicable
Hi,
I just realised I may be an idiot; you're after a calculated column, not a measure, right? In which case the following may not be relevant.
The DAX wasn't exact. If your source data has the week they occurred in as a column name, you can use that directly. If not, and you have some sort of date table, you may need to use the week number that is reference from that table.
You will need the table name e.g.
'Terms & Hires SQL'[Fiscal Week Ends]=currentweek
- V-lianl-msftCommunity Support
Hi Anonymous ,
Message 11 works well. Please try to create a similar DAX formula.
If you want to calculate with consecutive "week", you need to first create the year week column, then sort it with rankx function, and then use [sort] to represent the week based on the formula.
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.