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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
DavidGorgan
Regular Visitor

Conditional Column - PowerQuery - Detect if date is in the last 7 or 30 days

Hello,

 

I have a table that contains a date column ( [time_recorded]).

 

I'm currently trying to create a conditional column that will display the following values ("Past week", "Past Month", "Other").

 

I've tried the following formula:


= Table.AddColumn(#"Expanded bi sites", "period", each if  Date.IsInPreviousNDays([time_record], 7) = true then "Past 7 Days" else if Date.IsInPreviousNDays([time_record], 30) = true then "Past 30 Days" else "Other Period")

 

 

Please can someone advise?

4 REPLIES 4
amitchandak
Super User
Super User

@DavidGorgan , check if this can help

 


Table.AddColumn(#"Expanded bi sites", "period", each if Date.Date.IsInPreviousWeek([time_record]) = true then "Past week" else if Date.Date.IsInPreviousMonth([time_record]) = true then "Past Month" else "Other")

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hello @amitchandak,

Thank you for getting back to me.

I've tried the formula and I get the following error: 

"Expression.Error: The name 'Date.Date.IsInPreviousWeek' wasn't recognized. Make sure it's spelled correctly."

@DavidGorgan , My mistake, try like 

 

Table.AddColumn(#"Expanded bi sites", "period", each if Date.IsInPreviousWeek([time_record]) = true then "Past week" else if Date.IsInPreviousMonth([time_record]) = true then "Past Month" else "Other")

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hello @amitchandak,

 

Thank you for your reply again.

 

This formula goes through successfully but it still does not work - rows display "error".

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors