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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
JK87
Regular Visitor

Counting number of weekdays between column with start date and column with end date

Dear all,
I would like to requst your assistance on how to add a new column that counts the number of mondays (or any other day) between a date column with a starting date and a date column with an end date? 

Both DATE_START and DATE_END should be included in the calculation, but if DATE_START and DATE_END are the same date value it should should only copunt as one "monday".

 

JK87_0-1682705805166.png

 

I have the result, I would like in excel. I would however much prefer to have it in my Power Bi-model...

JK87_2-1682706418805.png

 

I hope you can help!

All the best,

Jacob

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@JK87 You can do something like this:

Measure = 
  VAR __Table = 
    ADDCOLUMNS(
      CALENDAR( [DATE_START], [DATE_END] ),
      "__WeekDay", WEEKDAY( [Date], 2 )
    )
  VAR __Result = COUNTROWS( FILTER( __Table, [__WeekDay] = 1) ) // this is for Monday
RETURN
  __Result

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
peter99_99_99
Regular Visitor

Please help me bellow 

thanks ahead

 

Original data
Work Date   ID       Qty amount
2023-02-28 FS-002 1 15
2023-02-28 FS-002 2 22
2023-02-28 FS-003 3 31
2023-02-28 FS-003 1 34
2023-02-28 FS-003 2 15
2023-02-28 FS-004 3 15
2023-02-28 FS-005 1 15
2023-02-28 FS-005 2 15
2023-02-28 FS-005 3 15
2023-02-28 FS-005 1 15
2023-02-28 FS-005 2 15
2023-02-28 FS-005 3 15
2023-02-28 FS-005 1 15
2023-03-01 FS-003 2 15
2023-03-01 FS-002 3 15
2023-03-01 FS-002 1 15
2023-03-01 FS-002 2 15
2023-03-01 FS-002 3 15
2023-03-01 FS-002 1 15

Expecting Result
Work Date   ID    Count Qty sum amount
2023-02-28 4 13 237
2023-03-01 2 6 90

JK87
Regular Visitor

Hi @Greg_Deckler ,
It works a treat! 
Thanks!

Greg_Deckler
Super User
Super User

@JK87 You can do something like this:

Measure = 
  VAR __Table = 
    ADDCOLUMNS(
      CALENDAR( [DATE_START], [DATE_END] ),
      "__WeekDay", WEEKDAY( [Date], 2 )
    )
  VAR __Result = COUNTROWS( FILTER( __Table, [__WeekDay] = 1) ) // this is for Monday
RETURN
  __Result

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.