Get certified for free when you join Fabric Data Days 2026 and dive into Fabric, Power BI, SQL, AI, and other essential data skills.
Join nowJuly 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more
I'm getting an error, but I dont know how to fix it. The error is coming from the "IfStatement" row.
Error:Expression.Error: The name 'DateTime.Month' wasn't recognized. Make sure it's spelled correctly.
I'm trying to say, If Month >= 8 then use 8/1/ current year, else use 8/1/ year - 1
let
Source = Sql.Database(".net", "database", [Query="select * from [dbo].[TableImUsing] where substring([TableColumnName], 1, 3) = 'XS ' and [Status] = 'Active' and [OtherStatus] in ('Pun')"]),
#"Added Prefix" = Table.TransformColumns(Source, {{"Column2", each "XS" & _, type text}}),
#"Changed Type" = Table.TransformColumnTypes(#"Added Prefix",{{"DAte2", type date}, {"Date1", type date}}),
#"IfStatement" = Table.SelectRows(#"Changed Type", if DateTime.Month(DateTime.LocalNow()) >= 8 then [Date1] > DateTime.Date(Date.Year(DateTime.LocalNow()), 8, 1) else [Date1] > DateTime.Date(DateTime.Year(Date.LocalNow())-1, 8, 1))
in
#"IfStatement"
Solved! Go to Solution.
I ended up breaking this out into several lines in order to simplify what I'm trying to get to.
This is what worked:
#"Added Custom" = Table.AddColumn(#"Changed Type", "Current Month Number", each Date.Month(DateTime.LocalNow())),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Current Year", each #date(Date.Year(DateTime.LocalNow()), 8, 1)),
#"Added Custom2" = Table.AddColumn(#"Added Custom1", "Prior Year", each #date(Date.Year(DateTime.LocalNow())-1, 8, 1)),
#"Added Conditional Column" = Table.AddColumn(#"Added Custom2", "FilterDate", each if [Current Month Number] >= 8 then [Current Year] else [Prior Year]),
#"Filtered Rows" = Table.SelectRows(#"Added Conditional Column", each [Date1] >= [FilterDate])
in
#"Filtered Rows"
I ended up breaking this out into several lines in order to simplify what I'm trying to get to.
This is what worked:
#"Added Custom" = Table.AddColumn(#"Changed Type", "Current Month Number", each Date.Month(DateTime.LocalNow())),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Current Year", each #date(Date.Year(DateTime.LocalNow()), 8, 1)),
#"Added Custom2" = Table.AddColumn(#"Added Custom1", "Prior Year", each #date(Date.Year(DateTime.LocalNow())-1, 8, 1)),
#"Added Conditional Column" = Table.AddColumn(#"Added Custom2", "FilterDate", each if [Current Month Number] >= 8 then [Current Year] else [Prior Year]),
#"Filtered Rows" = Table.SelectRows(#"Added Conditional Column", each [Date1] >= [FilterDate])
in
#"Filtered Rows"
I'm still getting an error, although now its different:
Expression.Error: There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?
let
Source = Sql.Database(".net", "database", [Query="select * from [dbo].[myTable] where substring([Campaign Name], 1, 3) = 'XS ' and [Status] = 'Active' and [OtherStatus] in ('Pun')"]),
#"Added Prefix" = Table.TransformColumns(Source, {{"ColumnA", each "XS" & _, type text}}),
#"Changed Type" = Table.TransformColumnTypes(#"Added Prefix",{{"Date2", type date}, {"Date1", type date}}),
#"IfStatement" = Table.SelectRows(#"Changed Type", if Date.Month( DateTime.Date( DateTime.LocalNow() )) >= 8 then [Date1] > DateTime.Date( Date.Year( DateTime.Date( DateTime.LocalNow())), 8, 1) else [Date1] > DateTime.Date( Date.Year(DateTime.Date(DateTime.LocalNow()))-1, 8, 1))
in
#"IfStatement"
Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.
If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!
Check out the July 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 30 | |
| 28 | |
| 25 | |
| 24 | |
| 16 |
| User | Count |
|---|---|
| 48 | |
| 32 | |
| 17 | |
| 16 | |
| 16 |