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
Anonymous
Not applicable

Passing range to DATESBETWEEN Power BI

I've been reading various threads and guides to performing a 'NETWORKDAYS' style calculation in Power BI but struggling to make it work.

I have a table like this:

Team |  Meeting    |  Report
aaa  | 1/1/2018    |  9/1/2018
aaa  | 1/1/2018    |  7/1/2018
bbb  | 1/1/2018    |  1/2/2018
bbb  | 1/1/2018    | 
ccc  | 1/1/2018    |  3/3/2018
aaa  | 1/1/2018    | 

And I want to return the average days without weekends and holidays, something like this:

Team | average
aaa  | 5 (10/2)
bbb  | 23 (45/1)
ccc  | 45 (45/1)

I have this non-working function:

Ave. weekdays to report = CALCULATE(AVERAGEX(DateTable[Weekday]),
                                    DATESBETWEEN(DateTable[Date],
        Planning[Meeting],Planning[Meeting]))

Where DateTable is:

Date    | Weekday
5/1/2018| 1
6/1/2018| 0
7/1/2018| 0

and so on...

My first problem is passing a table column to DATESBETWEEN returns an error. Other ideas I had were a SUMX looking at RELATEDTABLE but again, syntax is tripping me up.

Essentially, I want to iterate over Planning and count the dates between Meeting and Report from the Dates table, filtered by Weekday = 1.

1 ACCEPTED SOLUTION

VAR is a way of creating variables within a DAX measure. So, kind of what you are saying but really just think of them as variables just like in any other coding language.

 

The result (31) is the number of days, not hours.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

7 REPLIES 7
v-yuezhe-msft
Employee
Employee

@Anonymous,

Firstly, create a calculated column in your  table.

NetWorkingDays = 
IF (
    NOT(ISBLANK (Planning[Report])),
        CALCULATE (
            sum ( 'Date'[Weekday] ),
            DATESBETWEEN ( 'Date'[Date], Planning[Meeting], Planning[Report])
        ))


Secondly, create the following measures in your table.

Team number = CALCULATE(COUNTA(Planning[Team]),FILTER(Planning,NOT(ISBLANK(Planning[Report]))))
Average workingday = SUM(Planning[NetWorkingDays])/[Team number]


 


Regards,
Lydia 

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable


@v-yuezhe-msftwrote:

@Anonymous,

Firstly, create a calculated column in your  table.

NetWorkingDays = 
IF (
    NOT(ISBLANK (Planning[Report])),
        CALCULATE (
            sum ( 'Date'[Weekday] ),
            DATESBETWEEN ( 'Date'[Date], Planning[Meeting], Planning[Report])
        ))

 

 


@v-yuezhe-msft Thanks Lydia  but I'd rather not go down the calculated column route as I have a few of these to do and want to work with measures for practice also.

Greg_Deckler
Super User
Super User

The first parameter should be a Date/Time column.

 

https://msdn.microsoft.com/en-us/library/ee634557.aspx

 

Not sure why it would be generating an error unless it really isn't a Date/Time column?


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable


@Greg_Decklerwrote:

The first parameter should be a Date/Time column.

 

https://msdn.microsoft.com/en-us/library/ee634557.aspx

 

Not sure why it would be generating an error unless it really isn't a Date/Time column?


 

@Greg_DecklerI think that was the problem with that particular part - thanks

Greg_Deckler
Super User
Super User

Did you look at my Quick Measure for NETWORKDAYS?

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Net-Work-Days/m-p/367362

 

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable


@Greg_Decklerwrote:

Did you look at my Quick Measure for NETWORKDAYS?

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Net-Work-Days/m-p/367362

 

 


I hadn't before now. Thanks.

 

Is VAR simply a way of creating measures for use in the same function, rather than having two or three separate measures, which you then use in a separate function?

 

Also one other thing, I don't understand the results in the NetworkDaysHoursMinutes column - just 31hours?

VAR is a way of creating variables within a DAX measure. So, kind of what you are saying but really just think of them as variables just like in any other coding language.

 

The result (31) is the number of days, not hours.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.