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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Syndicate_Admin
Administrator
Administrator

My tables become outdated when I change Month.

Duda.png

MY problem is that they lost the months of onset when they accumulate what they enter.

1 ACCEPTED SOLUTION
AllisonKennedy
Super User
Super User

@Anonymous 

 

I would do this in Power Query, so instead of using the Advanced SQL code, leave that blank, click 'Transform Data' to open Power Query Editor in Power BI.

 

Click Home tab > Choose Columns. 

Select the same columns that are in your SQL SELECT statement.

 

Now click the filter arrow for the [time] column and set Filter to Date Filters > Custom Filter and set your filter options in Power Query. You can do a few different things, depending on your goal:

 

OPTION A: Select all dates in this current year

AllisonKennedy_0-1633134002297.png

Click OK. 

OPTION B: Select all dates from January 1, 2021 until today:

AllisonKennedy_1-1633134082709.png

Click OK.

Edit the Formula to replace #date(2021, 10, 2) with Date.From(DateTime.LocalNow())

 

= Table.SelectRows(#"Changed Type", each [Starttime] >= #date(2021, 1, 1) and [Starttime] <= Date.From(DateTime.LocalNow()))

AllisonKennedy_2-1633134153634.png

 

OPTION C: Edit your SQL statement

SQL is not my strongest language, thus why I said I would do this in Power Query, but you could update your SQL statement to use DATEFROMPARTS instead of DATEADD to fix it to January. https://docs.microsoft.com/en-us/sql/t-sql/functions/datefromparts-transact-sql?view=sql-server-ver15

 

@StartDate = DATEFROMPARTS(2021, 01, 01)

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

1 REPLY 1
AllisonKennedy
Super User
Super User

@Anonymous 

 

I would do this in Power Query, so instead of using the Advanced SQL code, leave that blank, click 'Transform Data' to open Power Query Editor in Power BI.

 

Click Home tab > Choose Columns. 

Select the same columns that are in your SQL SELECT statement.

 

Now click the filter arrow for the [time] column and set Filter to Date Filters > Custom Filter and set your filter options in Power Query. You can do a few different things, depending on your goal:

 

OPTION A: Select all dates in this current year

AllisonKennedy_0-1633134002297.png

Click OK. 

OPTION B: Select all dates from January 1, 2021 until today:

AllisonKennedy_1-1633134082709.png

Click OK.

Edit the Formula to replace #date(2021, 10, 2) with Date.From(DateTime.LocalNow())

 

= Table.SelectRows(#"Changed Type", each [Starttime] >= #date(2021, 1, 1) and [Starttime] <= Date.From(DateTime.LocalNow()))

AllisonKennedy_2-1633134153634.png

 

OPTION C: Edit your SQL statement

SQL is not my strongest language, thus why I said I would do this in Power Query, but you could update your SQL statement to use DATEFROMPARTS instead of DATEADD to fix it to January. https://docs.microsoft.com/en-us/sql/t-sql/functions/datefromparts-transact-sql?view=sql-server-ver15

 

@StartDate = DATEFROMPARTS(2021, 01, 01)

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.