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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
TBSST
Frequent Visitor

Calculating Number of Weeks in Date Slicer ignoring active Relationships

Hi PowerBI Community, 

 

I am currently working on a DAX to calculate the number of weeks a client has been active based on a callender date slicer. I use 3 dates, a start date, and end date, and a survey date. The survey date has an active relationship with the date in the callender table as the survey date is the most used date filter for most of the reports. The start and end date has an inactive relationship with the callender date table. 

 

The DAX i am needing is one that identifies how many weeks a client has been active during a month (determined by the date slicer). With this i also need to calculate with the start and end date included aswell, so if a client starts halfway through a month, it only counts from the start date, not the start of the month sleected, and same logic for end dates. 

 

The main issue i am having with this calculation is that when i filter with 'TheDate', on an individual client levle, it is counting the min date as the first activity they had that month. So an example is if im looking at 1/1/2024 ro 31/1/2024, and the first survey recorded for a cient is on the 10/1/2024, the count of number of weeks start at the 10th, not the first for that client. Is there a way to ignore this relationship of survey date and the callender, or a way to only count the date slicer regardless of when a survey was completed. 

 

Any help with DAX on this would be greathly appreaciated. Been spending quite some time trying to troubleshoot this one!

Client IDStart_DateEnd_DateSurveyIDSurvey_Date
CL-11/01/202429/02/2024SV-11/01/2024
CL-11/01/202429/02/2024SV-28/01/2024
CL-11/01/202429/02/2024SV-315/01/2024
CL-11/01/202429/02/2024SV-425/01/2024
CL-11/01/202429/02/2024SV-52/02/2024
CL-11/01/202429/02/2024SV-610/02/2024
CL-11/01/202429/02/2024SV-720/02/2024
CL-214/01/2024 SV-814/01/2024
CL-214/01/2024 SV-920/01/2024
CL-214/01/2024 SV-106/02/2024
CL-214/01/2024 SV-1110/02/2024
CL-310/02/2024 SV-1214/02/2024
CL-310/02/2024 SV-1320/02/2024
CL-310/02/2024 SV-1421/02/2024
CL-310/02/2024 SV-1529/02/2024
CL-420/01/202420/02/2024SV-1624/01/2024
CL-420/01/202420/02/2024SV-172/02/2024
CL-420/01/202420/02/2024SV-1810/02/2024
CL-420/01/202420/02/2024SV-1919/02/2024

Thank you. 

 

1 REPLY 1
BeaBF
Super User
Super User

@TBSST ! Hi!

First of all disactivate the relationship between the Calendar Table and the Survey Date. Then try to add this measures:

SelectedPeriodStartDate =
CALCULATE(
    MIN(Calendar[Date]),
    ALLSELECTED('Calendar')
)
 
SelectedPeriodEndDate =
CALCULATE(
    MAX(Calendar[Date]),
    ALLSELECTED('Calendar')
)
 
ActiveWeeks =
VAR StartDate = SELECTEDVALUE('Table'[Start_Date])
VAR EndDate = SELECTEDVALUE('Table'[End_Date])
VAR PeriodStart = [SelectedPeriodStartDate]
VAR PeriodEnd = [SelectedPeriodEndDate]

VAR ActualStart =
    IF(
        StartDate < PeriodStart,
        PeriodStart,
        StartDate
    )
VAR ActualEnd =
    IF(
        ISBLANK(EndDate),
        PeriodEnd,
        IF(
            EndDate > PeriodEnd,
            PeriodEnd,
            EndDate
        )
    )

VAR DaysActive = DATEDIFF(ActualStart, ActualEnd, DAY)
VAR WeeksActive = DIVIDE(DaysActive, 7, 0)

RETURN
IF(DaysActive > 0,
    CEILING(WeeksActive, 1),
    0
)
 
BeaBF_0-1717745250592.png
BBF

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.