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
HankScorpio
Frequent Visitor

Weekly results based off different start dates

 

I want to create a table with a list of names in the first column and 1 colums each representing the weekly results of an operator. 

However, The start dates will be different for some operators. 

 

For example 

AgentID       Name            Start date

ou812      Somebody 1     25/09/2023
ou813      Somebody 2     25/09/2023
ou814      Somebody 3     25/09/2023
ou815      Somebody 4     25/09/2023
ou816      Somebody 5     25/09/2023
ou817      Somebody 6     27/11/2023
ou818      Somebody 7     8/01/2024


I have created a measure for the operator results. 

 

My thinking is that I should be able to filter based on the start date and loop adding 7 to the start date each time and getting the result of the startdate + 5 (Monday to Friday) But Dax has no loop. 

 

effectively creating a list of weekly results dynaically

 

I tried to create a measure for just the 1st week and go from there. However, Start Date canot be determined because I haven't provided aggregation. Which i don't want to aggreagte I want to loop. I just can't figure out how to filter for each person based on there start date and then increasing the start date

 

Week 1 AHT = CALCULATE([Total AHT], DATESBETWEEN('date table'[Date], Staff[Start date], Staff[Start date]+7))
Week 1 AHT = CALCULATE([Total AHT], DATESBETWEEN('date table'[Date]+ 7, Staff[Start date], Staff[Start date]+14))

 

2 REPLIES 2
AnalyticsWizard
Solution Supplier
Solution Supplier

@HankScorpio 

 

In DAX, you indeed cannot use traditional loop constructs like in procedural programming languages. Instead, you can achieve a similar result by creating a series of measures that calculate values conditionally based on the start date and the current context on your report or visual.

 

However, to compare dates and calculate weekly results, we'll need to ensure that the 'Staff' table and the 'date table' are properly related in the model. Here's how you can calculate weekly results starting from each staff member's start date:

 

1.  Make sure you have a 'date table' that covers all the dates in your range and that it is marked as a date table in your model.

2. Set up a relationship between your 'Staff' table and 'date table' on the date columns.

3. In your 'Staff' table, add a calculated column to determine the week number since the start date for each date in your 'date table'.

 

Week Number Since Start =
INT(( 'date table'[Date] - Staff[Start date] ) / 7)

 

4. You will need to create individual measures for each week's AHT based on the 'Week Number Since Start'. Here's how you can write the measure for Week 1:

 

Week 1 AHT =
CALCULATE(
[Total AHT],
FILTER(
ALL('date table'),
'date table'[Date] >= MIN(Staff[Start date])
&& 'date table'[Date] < MIN(Staff[Start date]) + 7
),
REMOVEFILTERS(Staff)
)

 

5. Copy the measure and adjust it for subsequent weeks by changing the week window:

 

 

Week 2 AHT =
CALCULATE(
[Total AHT],
FILTER(
ALL('date table'),
'date table'[Date] >= MIN(Staff[Start date]) + 7
&& 'date table'[Date] < MIN(Staff[Start date]) + 14
),
REMOVEFILTERS(Staff)
)

 

 

By following these steps, you'll have a set of measures that can be used in your reports to display weekly results based on each staff member's start date. You can continue creating such measures for as many weeks as needed.

This approach does require you to create multiple measures, and it can be cumbersome if you have a lot of weeks to cover. An alternative approach for a more dynamic solution might be to use Power BI's built-in time intelligence functions in combination with calculated columns or to write more complex DAX code using `SUMMARIZE` and other functions to create a summary table dynamically within a measure.

 

Remember, if you have different start dates and need the weeks to be relative to each individual's start date, using `REMOVEFILTERS(Staff)` allows the calculation to consider each staff member's start date without being affected by row context in the 'Staff' table.

 

If this post helps, please consider Accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudo 👍

Hi 

 

Thanks for the detailed response. 

 

The first measure does not work as it cannot determine which 'date table'[Date] to use as there is no aggregation. 

 

Week Number Since Start =
INT(( 'date table'[Date] - Staff[Start date] ) / 7)

Which makes sense I think since there are months of dates covering all the start dates Dax cannot determine which one to use.

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.