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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
kleighton
Helper II
Helper II

Counting Workdays to be used in a Calculation on another table

Hi!

-I'm calculating Capacity% of a resource, based on 5 day week (including holidays) vs 7 day week * Resource Hrs/day.

I'm using a  calendar table and calculated column for workday:

 -Workday = IF(ISBLANK(Calender[Holiday]),IF(Calender[DayOfWeekNumber]<=5,1,0),0)
I have a measure to count these workdays per month: 
 -Workdays = CALCULATE(COUNT(Calender[Workday]),Calender[Workday]=1)
These are all working fine...
wdays.PNG
 
 
 
My data table; 
table.PNG
 
 
 
 
 
TotalDaysMonth = COUNTROWS ( PARALLELPERIOD ( Calender[Date], 0, MONTH))
7days% = DIVIDE ( (Query1[SUM(LOAD1)]), (RELATED (Resource[Hrs/Day]) * Query1[TotalDaysMonth]),0 )
 
So far, everything works fine, But when i try to calculate 5 days% as follows:
5days% = DIVIDE ( (Query1[SUM(LOAD1)]), (RELATED (Resource[Hrs/Day]) * [Workdays]),0 )
Where [Workdays] is my measure above:
It is returning 1 for the value of the [Workdays] measure and not the count for the Month..
There is a relationship between the tables, but how do i make the measure count the numbers of workdays for that row (Month)?
I guess i'm missing something simple but i can't think of it..
1 ACCEPTED SOLUTION

Hi,

 

Please take following steps:

1)Create two columns in Calendar and Query1 tables:

Year&Month = FORMAT('Calendar'[Date],"YYYY-MM")

Year&Month = FORMAT('Query1'[StartingDate],"YYYY-MM")

2)Try to create this column in Calendar table:

WorkDays per Month =
CALCULATE (
    COUNT ( Calendar[Workday] ),
    FILTER (
        ALLSELECTED ( 'Calendar' ),
        'Calendar'[YearMonthnumber] = EARLIER ( 'Calendar'[YearMonthnumber] )
            && Calendar[Workday] = 1
    )
)

3)Try to create this column in Query1 table:

WorkDays per Month = RELATED('Calendar'[WorkDays per Month])

4)Try this column to show the 5days% expected result:

5days% = DIVIDE ( (Query1[SUM(LOAD1)]), (RELATED (Resource[Hrs/Day]) * Query1[WorkDays per Month]),0 )

5)The result shows:

6.PNG

Here is the changed pbix file:

pbix 

Hope this helps.

 

Best Regards,

Giotto

 

View solution in original post

8 REPLIES 8
v-gizhi-msft
Community Support
Community Support

Hi,

 

Could you please create and share some simple sample and expected result as screenshots with me?

And it can let me help you further and more efficiently.

Remember removing any sensitive data.

Expect your reply!

 

Best Regards,

Giotto

Hi,

 

Thanks everyone for the posts, unfortunately it hasn't helped. below is a recreated sample of my file in its original state, before the various modifications suggested above and without private data sources. 

https://www.dropbox.com/s/e7nbm1fjjb2q2sj/ResCapactiySample.pbix?dl=0

 

 The 5day% calculation is the problem, Expected result sample as follows:

5days% for Res5 on October 2020 =

(Query1[SUM(LOAD1) 235.66 / ((Resource[Hrs/Day]) 21 * [Workdays] 22)= 51%
 
p.s I also noticed i had Calendar mistyped as Calender 🙂 now corrected..
Thanks everyone for their input
Keith

 

Hi,

 

Please take following steps:

1)Create two columns in Calendar and Query1 tables:

Year&Month = FORMAT('Calendar'[Date],"YYYY-MM")

Year&Month = FORMAT('Query1'[StartingDate],"YYYY-MM")

2)Try to create this column in Calendar table:

WorkDays per Month =
CALCULATE (
    COUNT ( Calendar[Workday] ),
    FILTER (
        ALLSELECTED ( 'Calendar' ),
        'Calendar'[YearMonthnumber] = EARLIER ( 'Calendar'[YearMonthnumber] )
            && Calendar[Workday] = 1
    )
)

3)Try to create this column in Query1 table:

WorkDays per Month = RELATED('Calendar'[WorkDays per Month])

4)Try this column to show the 5days% expected result:

5days% = DIVIDE ( (Query1[SUM(LOAD1)]), (RELATED (Resource[Hrs/Day]) * Query1[WorkDays per Month]),0 )

5)The result shows:

6.PNG

Here is the changed pbix file:

pbix 

Hope this helps.

 

Best Regards,

Giotto

 

Perfect, Thankyou Giotto!!! 

v-gizhi-msft
Community Support
Community Support

Hi,

 

Please try this measure:

5days% =
DIVIDE (
    ( Query1[SUM(LOAD1)] ),
    (
        RELATED ( Resource[Hrs/Day] )
            * CALCULATE (
                [Workdays],
                FILTER (
                    ALLSELECTED ( Calender ),
                    Calender[Date].[Month] IN FILTERS ( Calender[Date].[Month] )
                )
            )
    ),
    0
)

If you still have any issue, please share more info about your Resource table such as [Hrs/Day] data and these three tables relationships(including link columns) as screenshots. And these can let me help you further.

Expect your reply!

 

Best Regards,

Giotto

parry2k
Super User
Super User

@kleighton change measure for workday in the divide function like this, it will give you workdays across the full month for each month

 

CALCULATE ( SUM ( 'Calendar'[Workday] ),  ALLSELECTED ( 'Calendar'[Date] ) ) 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

amitchandak
Super User
Super User

Can you share sample data and sample output.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Greg_Deckler
Super User
Super User

First, sample data. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

Second, I generally have more luck with RELATEDTABLE vs. RELATED.



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
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.