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
jd8766
Helper II
Helper II

Filter unrelated fact table based on date selection?

Hoping somebody has a solution for this.. as I can't figure it out myself.

I have a Sales fact table that contains the details of all sales made within a time period. This is joined onto a SoldUser dimension and a SoldDate dimension.

jd8766_0-1667826198279.png


I also have an unrelated FACT table which shows the details of any days off work an employee has had
FACT.NotWorked

jd8766_1-1667826226890.png


I want to have a slicer on my report for sold date, so I can see sales between '01 aug 2022' and '3 nov 2022' but then I also want it to show me how many days each sold user worked between the 2 selected dates (excluding weekends and any entries in the FACT.NotWorked table)

Is this doable? So we can see in the bottom table, UserKey 40 has not worked 11 days between '01 aug 2022' and '3 nov 2022' so I would need these 11 days to be taken off the total days worked measure.. if that makes sense?

Is this achievable in Power BI? How could I do this?


 



1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

See if this works for you. First the model (I've joined the User table to the leave table)

model.jpg

and the measures

Leave Weekdays  Temp = 
IF(ISINSCOPE('User Table'[SoldUserkey]),
COUNTROWS (
    FILTER (
        ALLSELECTED ( 'Date Table' ),
        'Date Table'[Date] >= MIN ( 'Leave Table'[LeaveStart] )
            && 'Date Table'[Date] <= MAX ( 'Leave Table'[LeaveEnd] )
            && WEEKDAY ( 'Date Table'[Date], 2 ) < 6
    )
)//Counts the number of dates which are >= LeaveStart and <= LeaveEnd and are not on the weekend
)
Final Working days =
VAR _NWD =
    NETWORKDAYS ( MIN ( 'Date Table'[Date] ), MAX ( 'Date Table'[Date] ) ) //Calculates the numbero of working days selected (excludes weekends)
VAR _LWD =
    SUMX ( 'Leave Table', [Leave Weekdays  Temp] ) //Calculates the sum of leave days which are on working days
RETURN
    _NWD - _LWD

Result.jpg

Sample PBIX Attached 

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

3 REPLIES 3
PaulDBrown
Community Champion
Community Champion

See if this works for you. First the model (I've joined the User table to the leave table)

model.jpg

and the measures

Leave Weekdays  Temp = 
IF(ISINSCOPE('User Table'[SoldUserkey]),
COUNTROWS (
    FILTER (
        ALLSELECTED ( 'Date Table' ),
        'Date Table'[Date] >= MIN ( 'Leave Table'[LeaveStart] )
            && 'Date Table'[Date] <= MAX ( 'Leave Table'[LeaveEnd] )
            && WEEKDAY ( 'Date Table'[Date], 2 ) < 6
    )
)//Counts the number of dates which are >= LeaveStart and <= LeaveEnd and are not on the weekend
)
Final Working days =
VAR _NWD =
    NETWORKDAYS ( MIN ( 'Date Table'[Date] ), MAX ( 'Date Table'[Date] ) ) //Calculates the numbero of working days selected (excludes weekends)
VAR _LWD =
    SUMX ( 'Leave Table', [Leave Weekdays  Temp] ) //Calculates the sum of leave days which are on working days
RETURN
    _NWD - _LWD

Result.jpg

Sample PBIX Attached 

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Nishudhan
Frequent Visitor

Yes it is doable.

You have to use NETWORKDAYS(start_date,end_date,weekends,holidays)

 

Thanks.

NETWORKDAYS only brings back the working days between 2 dates.. I also want it to exclude any days not worked based on the 2nd table

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.