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

View all the Fabric Data Days sessions on demand. View schedule

Reply
ngadiez
Helper II
Helper II

Get Date Value from Parameters

I have 2 parameters where I get the 'Valuation Year' and 'Valuation Month'

 

I want to use these 2 parameters to add custom Column:

 

This is my code: I want to get the difference in month:

Number.RoundUp(Duration.Days(Date(ValuationYear,ValuationMonth,31)-[StartDate])/30)

 

However Date wasn't recognized. 

Is there any other way to get it?

 

StartDate is in Date format.

1 ACCEPTED SOLUTION

If only year/month is relevant, then you can use the following code, in which <PreviousStep> is the name of the previous step in your query.

 

= Table.AddColumn(<PreviousStep>, "Months", each 12*(ValuationYear-Date.Year([StartDate]))+ValuationMonth-Date.Month([StartDate]))
Specializing in Power Query Formula Language (M)

View solution in original post

3 REPLIES 3
MarcelBeug
Community Champion
Community Champion

It looks like you want to use #date, however, #date won't accept 31 for months with less than 31 days.

Also dividing by30 doesn't look like a good idea to me.

 

Can you specify exactly how you need the number of months to be calculated?

E.g:

April 30 to May 1 is 0 or 1 month?

April 15 to May 14 is 0 or 1 month?

April 1 to May 31 is 1 month (or 2)?

 

Specializing in Power Query Formula Language (M)

If only year/month is relevant, then you can use the following code, in which <PreviousStep> is the name of the previous step in your query.

 

= Table.AddColumn(<PreviousStep>, "Months", each 12*(ValuationYear-Date.Year([StartDate]))+ValuationMonth-Date.Month([StartDate]))
Specializing in Power Query Formula Language (M)

Thank you @MarcelBeug

 

The day is irrelevant here.

Yes your solution is correct.

 

Thanks a lot.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors