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
msuser48
Helper I
Helper I

Subtract months from two date columns, and drill down on date

I have this table:

IDStartDateEndDateYearMonth (must be calculated column)
12000-01-012001-01-0110
22000-01-012002-01-0221
32000-01-012000-29-12011
42000-01-012003-01-0635
51990-01-051995-01-0752
62000-01-012005-01-0655

 

I want to solve 2 problems:

 

PROBLEM 1)

How do I create the desired output (month column) in a calculated column? I need to the month value of EndDate minus the month value of StartDate to do this, I suppose.

- Example: For ID 3: 12 minus 01 gives the correct value = 11.

PROBLEM 2)
When I have this above table with year and month, I need a column chart with this drill down logic:

- This below shows how many rows have the 0, 1, 2, 3, 4, and 5 value in the year column.

msuser48_0-1669846087032.png

If I then click "0", it should drill down, and show me how many rows, for year 0 only, there are for each month value, like this:

msuser48_0-1669846479277.png

How to accomplish this?

 

 

1 ACCEPTED SOLUTION

Hi @msuser48,

According to your description, it seems like you want to get the diff on month level of date values.

If that is the case, you can try to use month function to extract the month number from 'start/end' date, then you can simply to get the difference.

 

diff =
MONTH ( [End Date] ) - MONTH ( [Start Date] )

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

5 REPLIES 5
Mahesh0016
Super User
Super User

In drill down you should TURNOFF Keep All Filters .

Mahesh0016
Super User
Super User

Month = MONTH('Subtract months'[EndDate])-MONTH('Subtract months'[StartDate])
 
 
for month solutions.
 
amitchandak
Super User
Super User

@msuser48 , Based on what I got two columns 

 

Year = Quotient(datediff([Start Date], [End Date], Month)+1, 12)

 

 

Month= Month(datediff([Start Date], [End Date], Month)+1, 12)

@amitchandakthanks, but this doesn't work. It says "too many arguments passed to month function. Max argument count is 1.

For the second problem also, how do I make the drill down described in problem 2, if you know?

Hi @msuser48,

According to your description, it seems like you want to get the diff on month level of date values.

If that is the case, you can try to use month function to extract the month number from 'start/end' date, then you can simply to get the difference.

 

diff =
MONTH ( [End Date] ) - MONTH ( [Start Date] )

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.