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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Add a dynamic "Days of Last Month" column in Query Editor

I'm trying to add a custom column to my table that would dynamically list the days of last month.

 

Example: 

In October the table would have rows:

  • 1/9/18
  • 2/9/18
  • ...
  • 29/9/18
  • 30/9/18

 

In November:

  • 1/10/18
  • 2/10/18
  • ...
  • 30/10/18
  • 31/10/18

 

I've been drilling into the Date functions (documented here) but can't see one that would cater to this requirement.

 

Is this function possible?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I ended up merging both queries based on the date column. After expanding the merge, filtering some blank/"null" rows, removing duplicates and filtering appropriately I was able to cobble together my solution.

View solution in original post

3 REPLIES 3
ChrisMendoza
Resident Rockstar
Resident Rockstar

@Anonymous,

 

What is the correct answer for when the previous month exceeds the current month, e.g. Nov has 30 days where Oct has 31? Also notice rows 30 & 31 where Sept 30 is repeated.

 

Did you try Date.AddMonths ( )?

 

Of course I am presuming you have a Date column with a contiguous date range.

 

Custom Column = Date.AddMonths ( [Date], -1 )

1.PNG






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Anonymous
Not applicable

I don't currently have a column of the current month. I'm happy to add whatever else I need to make this work though.

 

Edit: I should state that I don't know of a function that just lists all of the days of the current month. I anticipate the same issue you raised for months when there are 30 vs 31 days and using a function that is (date) - 1.

 

The issue I'm trying to solve is that I have 2 sets of data, with no unique fields to create a relationship. So I was trying to create some sort of "joiner" table of data that could hold unique dates and relate those to the duplicate dates in each other table.

 

I suppose another thing I could investigate is copying a column from another table and just removing duplicates. Bit hacky but it might serve..

Anonymous
Not applicable

I ended up merging both queries based on the date column. After expanding the merge, filtering some blank/"null" rows, removing duplicates and filtering appropriately I was able to cobble together my solution.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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