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
salman_ali
Helper IV
Helper IV

last week

hello all pls help me get to LAST WEEK, i have gotten 'thisweek', 'last2weeks' & 'Notthisweek'

 

ThisWeek1 = if([Week_Ending]>=now(),if([Week_Ending]-now()<7,"ThisWeek","NotThisWeek"),if(now()-[Week_Ending]<14,"Last2Weeks","NotThisWeek"))
3 REPLIES 3
salman_ali
Helper IV
Helper IV

This is what I used

 

last_week = SWITCH(TRUE(),
AND(DATEDIFF('Date'[Week_Ending],TODAY(),DAY)<0,
DATEDIFF('Date'[Week_Ending],Today(),DAY)>=-7),"ThisWeek",

AND(DATEDIFF('Date'[Week_Ending],TODAY(),DAY)>=0,
DATEDIFF('Date'[Week_Ending],Today(),DAY)<=7),"LastWeek",

AND(DATEDIFF('Date'[Week_Ending],Today(),DAY)>=0,
DATEDIFF('Date'[Week_Ending],TODAY(),DAY)<=13),"Las2Weeks",

DATEDIFF('Date'[Week_Ending],Today(),DAY)>=14,"NotThisWeek")
 
Week Ending date is date on sunday each week 
dax
Community Support
Community Support

Hi @salman_ali , 

I am not clear  about your requirement, if you want to create a column to define weekname, you could try below M code

let
    Source = List.Dates(#date(2020,4,1), 30, #duration(1,0,0,0)),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Added Custom" = Table.AddColumn(#"Converted to Table", "Custom", each if Date.IsInCurrentWeek([Column1]) then "current week" else if Date.IsInPreviousNWeeks([Column1], 1) then "last 1 week"  else if Date.IsInPreviousNWeeks([Column1], 2)  then "last 2 week"  else null)
in
    #"Added Custom"

If this is not what you want, could you please inform me more detailed information(such as your expected output and your sample data (by OneDrive for Business))? Then I will help you more correctly.

Please do mask sensitive data before uploading.

Thanks for your understanding and support.
Best Regards,
Zoe Zhi

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

amitchandak
Super User
Super User

@salman_ali , Please refer to this file, I have used week rank to get this week, last week rolling week. Typically same weekday is 7 days behind.

7 Days behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-7,Day))

 

The above is one method. Check this file: https://www.dropbox.com/s/d9898a48e76wmvl/sales_analytics_weekWise.pbix?dl=0

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.