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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
ThomasWeppler
Impactful Individual
Impactful Individual

How do I selected right number of date in multiple months in Power.query?

Hi power Bi community

I want to make a table that shows how often an assignment is reopended.

I get the information from a freetext colum (unfortunately). 
Where I have tried to make a lot of logic in PowerQuery to make it fit.

One of my problems is that they have made an interval where they write x (a number) months.

I have made a table where I can see the first date, the interval in months (x) and all the dates in the next three years where I try to see if this matches the selected dates.

Example: if the first date is the first of january 2024 and x months = 2 than the the correct dates would be 

first of january 2024, first of marts 2024 first of may 2024 first of July 2024 and so forth


To do this I have made a table with
[FirstDate] = the first day the assingment start

[Date] = a colum with all dates the next three years

[interval] = the number of months between each time the assignment should be completed.
[True] = a new (true/false) colum I want to make where I see if the date = firstdate + one or more intervals of months

I tried to solved it with this line: 
Date.AddMonths([FirstDate],Number.RoundUp((Duration.Days([Date]-[FirstDate])/30)/[interval])*[interval])

My problem is that not all months have 30 days. So overtime it stops working. I have tried to change the 30 to 31 and 30.5 and it helps, but it is still not ideal.

 

I think I need to calculate exactly how many months have passed with a formel or change the formel so it looks at days instead of months, but I am not quite sure.

All help will be greatly appreciated.

1 ACCEPTED SOLUTION
ThomasWeppler
Impactful Individual
Impactful Individual

Ok I found a solution, but it requires a diffrent approach.
First I check if the date of the months are the same in the two columns.

= if Date.Day([Date]) = Date.Day([FirstDate]) then
Number.Round(Number.From(([Date] - [FirstDate])/( 365.25 / 12 )) ,0 )/[Number]
else 0)
I then make a new colum where I changes all rows containing a "," to 0 as well.

At the end I can just check if the value is > 0.

 

I have the solution now so a moderator can just close this thread.

View solution in original post

6 REPLIES 6
ThomasWeppler
Impactful Individual
Impactful Individual

Ok I found a solution, but it requires a diffrent approach.
First I check if the date of the months are the same in the two columns.

= if Date.Day([Date]) = Date.Day([FirstDate]) then
Number.Round(Number.From(([Date] - [FirstDate])/( 365.25 / 12 )) ,0 )/[Number]
else 0)
I then make a new colum where I changes all rows containing a "," to 0 as well.

At the end I can just check if the value is > 0.

 

I have the solution now so a moderator can just close this thread.

All that you need to do is mark the reply to the post as a solution to mark as closed.

ThomasWeppler
Impactful Individual
Impactful Individual

@foodd Thanks for the tip.

ThomasWeppler
Impactful Individual
Impactful Individual

Hey @Anonymous 
I tried that but I don't know how to use the [DateColumn] in this case.
If I just use my DateColumn it will divide all months by 30 or 31 depending on the choosen date the selected months.
So if the date column in a specific row is in August and looking 3 months back it will divide with 31*3 where it really should only divide with (31+30+31).

Anonymous
Not applicable

You can replace "30" with

 

Date.DaysInMonth([DateColumn])

 

--Nate

foodd
Super User
Super User

Please provide your work-in-progress Power BI Desktop file (with sensitive information removed) that covers your issue or question completely in a usable format (not as a screenshot).

https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

This allows members of the Forum to assess the state of the model, report layer, relationships, and any DAX applied.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors