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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculating Previous Values

Hi, 
 
I am posting the same question again in hopes of finding the answer. I need to calculate the value for the past two weeks from Net Hire column. The dax measure I have is not giving me any values and I do not see where the mistake is, I've reformatted it multiple times but I cannot get it to show the values. Can someone please help? 
 
UnknownValue_1-1643674143784.png

Last 2 Weeks new =

VAR Fiscal_Week_End = MAXA ('Terms & Hires SQL'[Fiscal Week Ends])
VAR Net_Hires = CALCULATE (SUM('Terms & Hires SQL'[Net Hires]),
 
FILTER (ALL ('Terms & Hires SQL'),
'Terms & Hires SQL'[Fiscal Week Ends] < Fiscal_Week_End))

 

Var cal = CALCULATE(SUM('Terms & Hires SQL'[Net Hires]),

 

FILTER (ALL('Terms & Hires SQL'[Net Hires]),
'Terms & Hires SQL'[Fiscal Week Ends] >= Fiscal_Week_End
&& 'Terms & Hires SQL'[Fiscal Week Ends] <= Fiscal_Week_End))

 

RETURN
cal
1 ACCEPTED SOLUTION
Anonymous
Not 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]=currentweek

var previousweekhires = 
CALCULATE( 
                   SUM(
                               'Terms & Hires SQL'[Net Hires]),
                            [Fiscal Week End]=previousweek

 

 

return

currentweekhires+previousweekhires

View solution in original post

14 REPLIES 14
V-lianl-msft
Community Support
Community 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.

Anonymous
Not 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]=currentweek

var previousweekhires = 
CALCULATE( 
                   SUM(
                               'Terms & Hires SQL'[Net Hires]),
                            [Fiscal Week End]=previousweek

 

 

return

currentweekhires+previousweekhires

Anonymous
Not applicable

That didn't work even when I found the columns.... 

UnknownValue_1-1643679455346.png

 

 

Anonymous
Not applicable

My calculated column DAX is rusty, but here's a basic measure that'll do the job

zhivana_0-1643683489520.png

 

LAST2WEEKSm =
var currentweek = max(Table1[Fiscal Week Number])
var previousweek = currentweek-1

var currentweeknethires =
CALCULATE(
SUM(
Table1[Net Hires]),
Table1[Fiscal Week Number]=currentweek
)

var previousweeknethires =
CALCULATE(
SUM(
Table1[Net Hires]),
Table1[Fiscal Week Number]=previousweek
)

return
currentweeknethires+previousweeknethires



Anonymous
Not applicable

Close? Because fiscal weeks differ from actual week numbers, for example, last week was Fiscal Week # 52 of 2021 and this week is Fiscal Week # 1 of 2022.

So there will be a break in count, even though the dates on which fiscal weeks are consecutive... 

For example: 

Fiscal Week 50 of 2021

Fiscal Week 51 of 2021

Fiscal Week 52 of 2021 

Fiscal Week 1 of 2022

 

I don't think that week number is a good value to use, I changed it Fiscal Week End Date in hopes that it would just work but it did not. 

 

UnknownValue_0-1643683890493.png

 

Anonymous
Not 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

TheoC
Super User
Super User

@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

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Anonymous
Not 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 date 

Dataset contains other columns that will be used as filters, location for example, so the values in the measure should change with the filters. 

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 

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Anonymous
Not applicable

this is giving me the same value as net hires....

 

UnknownValue_0-1643681427201.png

 

Sorry mate, just change VAR _1 to the following: 

 

VAR _1 = LASTDATE ( 'Table'[Date] ) - 7

 

So the whole measure will be:

 

14 Days = 

VAR _1 = LASTDATE ( 'Table'[Date] ) - 7 // 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 ) ) )

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Anonymous
Not applicable

Now it's blank...I am trying to tinker with it myself too by the way....

 

UnknownValue_0-1643682321582.png

 

@Anonymous try the below:

 

14 Days = 

VAR_1 = LASTDATE ( 'Terms & Hires SQL'[Fiscal Week Ends] ) - 7
VAR_2 = _1 - 14
RETURN
CALCULATE ( SUM ('Terms & Hires SQL'[Net Hires] ) , FILTER ( ALL ( 'Terms & Hires SQL'[Fiscal Week Ends]) , AND ( 'Terms & Hires SQL'[Fiscal Week Ends] > _2 , 'Terms & Hires SQL'[Fiscal Week Ends] <= _1 ) ) )

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Anonymous
Not applicable

It was giving me errors so I modified it (bottom snip)

 

UnknownValue_0-1643683136981.pngUnknownValue_1-1643683226226.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.