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!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! 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"
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 40 | |
| 36 | |
| 33 | |
| 29 | |
| 26 |
| User | Count |
|---|---|
| 135 | |
| 103 | |
| 65 | |
| 61 | |
| 55 |