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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

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.



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

7 REPLIES 7
v-yuezhe-msft
Microsoft Employee
Microsoft 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?



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

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

 

 



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

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.



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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