Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by watching the DP-600 session on-demand now through April 28th.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
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"
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 48 | |
| 40 | |
| 38 | |
| 20 | |
| 17 |
| User | Count |
|---|---|
| 68 | |
| 66 | |
| 30 | |
| 26 | |
| 25 |