Forum Discussion
How to create this special date column?
Hi everyone,
I want to create a new column in Power BI like the following example:
The previous rows are the first day of each month, but the last row is the current date.
How to write the query?
Thanks,
Changlin
Changlin ,
Create a table like
Filter(calendar(Eomonth(today(), -12) +1, Today()), [Date] = eomonth([Date],0) || [Date] = today())
Try:
let Source = List.Generate( () => #date(2021, 8, 1), each Number.From(_) < Number.From(Date.AddMonths(DateTime.LocalNow(), 1)), each Date.AddMonths(_, 1), each if _ = DateTime.Date(Date.StartOfMonth(Date.AddMonths(DateTime.LocalNow(), 1))) then DateTime.Date(DateTime.LocalNow()) else _ ) in SourceRegards
6 Replies
- amitchandakSuper User
Changlin ,
Create a table like
Filter(calendar(Eomonth(today(), -12) +1, Today()), [Date] = eomonth([Date],0) || [Date] = today())
- ChanglinFrequent Visitor
Thanks for answering, with your query I got the following
But I need the first day of month, so I made some changes with the query
Filter(calendar(Eomonth(today(), -12) +1, Today()), [Date] = eomonth([Date], -1) +1 || [Date] = today())Then I got the result that I needed
Thank you so much!
- Jos_WoolleySolution Sage
Alternative for Power Query:
let Source = List.Generate( () => #date(2021, 8, 1), each Number.From(_) < Number.From(DateTime.LocalNow()), each Date.AddMonths(_, 1), each if _ = DateTime.Date(Date.StartOfMonth(DateTime.LocalNow())) then DateTime.Date(DateTime.LocalNow()) else _ ) in SourceI have hard-coded your starting date (2021,8,1) here, though you could change this to a dynamic reference if desired.
Regards
- ChanglinFrequent Visitor
Thanks for answering, this power query works great!
But if I want to keep both the first of current month and current date, how to do it?
- Jos_WoolleySolution Sage
Try:
let Source = List.Generate( () => #date(2021, 8, 1), each Number.From(_) < Number.From(Date.AddMonths(DateTime.LocalNow(), 1)), each Date.AddMonths(_, 1), each if _ = DateTime.Date(Date.StartOfMonth(Date.AddMonths(DateTime.LocalNow(), 1))) then DateTime.Date(DateTime.LocalNow()) else _ ) in SourceRegards