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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
rast286
Frequent Visitor

DAX Formular count days over month between two days

Hello everybody,

I have following problem and hope anybody could help me out.

 

I have to count the days of businesstrips of our employees over the month.

A businesstrip always has a startdate and an enddate. If no enddate is available the businesstrip is still going.

We want to see how many days our employees were on bussinestrip in January, February, March, etc... 

 

For me, the difficult thing is, when a businesstrip went over two or more month.

For example:

Trip Nr. 1 Startdate 27.01.2023, Enddate 04.03.2023.

That are 5 days in January, 28 days in February and 4 days in March.

 

Trip Nr. 2 Startdate 25.02.2023, Trip still ongoing

That are 4 days in February and 14 days in march (because today is March the 14.th)

 

Hope the infos are enough and someone could help me.

 

Thanks in advance!

 

Ralph

2 ACCEPTED SOLUTIONS
Ahmedx
Super User
Super User

1) You need to create a calendar table
1.png2.png
2) write measure like this:
3.png4.png

3)Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
https://1drv.ms/u/s!AiUZ0Ws7G26RhjvgpTWw9G7Cx3jl?e=X6i7Qh

View solution in original post

11 REPLIES 11
Ahmedx
Super User
Super User

1) You need to create a calendar table
1.png2.png
2) write measure like this:
3.png4.png

3)Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
https://1drv.ms/u/s!AiUZ0Ws7G26RhjvgpTWw9G7Cx3jl?e=X6i7Qh

One more Question...
is it also possible to get the totals in the respective month?
For example like this?

rast286_0-1679041900739.png

I have tried it by my own but I am pretty new in writing DAX measures.

 

Regards

 

Ralph

Screen Capture #634.png

Thanks for your fast reply.
Worked great.

Thanks a lot!!

Regards

Hi Ahmedx,

awesome! Just tried it and it worked great.

Thanks a lot!

Best wishes 

Ralph

Ahmedx
Super User
Super User

or maybe you just want a calculated column
Screen Capture #569.png

No the first one would be the right solution.

The one with the month.
Would be nice to know how you did that? 

i already answered

Ahmedx
Super User
Super User

Is this what you are looking for?

Screen Capture #567.png
Screen Capture #566.png

Exactly!

BITomS
Responsive Resident
Responsive Resident

Hi @rast286,

 

My suggestion would be to generate a row for each day between the start and end dates by unpivoting the data. Then you can perform a simple count on the number of rows (which can then be sliced by month, employee etc.).

 

This article could be useful for your purposes: https://natechamberlain.com/2018/08/08/how-to-add-rows-for-dates-between-start-and-end-dates-in-powe...

 

Hope that helps.

 

 

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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