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
electrobrit
Post Patron
Post Patron

Hours available per week based on a standard hours (then adjusting based on conditions

Hoping someone can assist with this issue: (seems simple but it's not for me)
I am trying to get a table with these fields from the data in the pbix file attached.


electrobrit_0-1664407536517.png

Note: I have a condition when it's listed as "Employee" that "final adjusted hours" Is available hours minus total PTO
If "Contractor"-final adjusted hours is equal to "Hours Worked" which is in the data
If the person is "Andy"-final adjsuted hours is equal to "hours worked"

 

I am doing everything in power query because I was having issues with the conditional columns in Dax. I've spent a lot of time trying both ways and that seemed to make more sense.
When i get the columns added and do the table visual it doesn't work. There are 2 lines for each date if the person has PTO. (the sample pbix attached shows what it's doing)
I would like it to be by person, by date (one row per date per person with data)-this is how it should be below.

electrobrit_1-1664408213156.png

I have added the pbix with 2 tabs where I tried it different ways and have issues on both. I feel like it's the standard hours table (I've merged and tried to not merge)
Can someone help me get to final table I am trying to get to? I am stumped and I've searched and searched but at the point I don't even know what it's doing and what to search anymore.
If you have a better idea using dax or anything, I'm ok with whatever works! THANK YOU in advance

Sample PBIX 

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @electrobrit ,

You can try the following dax

Column =
VAR _PTOSUM=SUMX(FILTER(ALL(TimeDetail),'TimeDetail'[period_end_date]=EARLIER('TimeDetail'[period_end_date])&&'TimeDetail'[resource_type_code]=EARLIER('TimeDetail'[resource_type_code])&&
CONTAINSSTRING('TimeDetail'[task_type_name],"PTO")=TRUE()),[PQ_TOTAL PTO])
RETURN
SWITCH(
    TRUE(),
    'TimeDetail'[full_name]="Andy",[hours_worked],
    'TimeDetail'[resource_type_code]="Employee",[PQ.Available Hours] - _PTOSUM,
    'TimeDetail'[resource_type_code]="Contractor",[hours_worked])

 

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yangliu-msft
Community Support
Community Support

Hi  @electrobrit ,

You can try the following dax

Column =
VAR _PTOSUM=SUMX(FILTER(ALL(TimeDetail),'TimeDetail'[period_end_date]=EARLIER('TimeDetail'[period_end_date])&&'TimeDetail'[resource_type_code]=EARLIER('TimeDetail'[resource_type_code])&&
CONTAINSSTRING('TimeDetail'[task_type_name],"PTO")=TRUE()),[PQ_TOTAL PTO])
RETURN
SWITCH(
    TRUE(),
    'TimeDetail'[full_name]="Andy",[hours_worked],
    'TimeDetail'[resource_type_code]="Employee",[PQ.Available Hours] - _PTOSUM,
    'TimeDetail'[resource_type_code]="Contractor",[hours_worked])

 

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I was able to get this to add the column with no errors, but it is not working like it should. It still does 2 rows per person if they have PTO and the final number is sometimes negative. 

electrobrit_2-1664478676737.png

 

 

 

It seems like the one column you suggested isn't achieving the goal of the table I said I was trying to get (screenshot above). Anyone else have any ideas? Am I missing something in explaining or is this just not possible or a stumper for everyone? 

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.