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
raimon
Resolver II
Resolver II

Split data across week

Hi All, 

 

I am struggling with one calculation. I have weekly data mapped to Sundays.

The date contains data of the prior week. 

 

Data- 

SchemeStart DateEnd Date
Scheme15-Jul-202-Aug-20
Scheme25-Jul-2019-Jul-20
Scheme312-Jul-209-Aug-20

 

If a scheme is running for 2 weeks, for both weeks there should be a count. 

 

Example Output - 

Week DateScheme1Scheme2Scheme3Total
5-Jul-2011 2
12-Jul-201113
19-Jul-201113
26-Jul-201 12
2-Aug-201 12
9-Aug-201  1

 

Please help with how do I calculate so that I can get proper count.

Also note I have some data which has start and end date an year apart. 

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

Hi, @raimon ;

You could create a date table about every sunday, then create a measure to calculate the count like below:

1.create a date table.

Date = FILTER( ADDCOLUMNS( CALENDAR(DATE(2020,7,1),DATE(2020,9,1)),"weekday",WEEKDAY([Date],2)),[weekday]=7)

2.create a measure.

Measure = 
var _value=CALCULATE(COUNT('Table'[Scheme]),FILTER(ALL('Table'),[Scheme]=MAX('Table'[Scheme])&&[Start Date]<=MAX('Date'[Date])&&[End Date]>=MAX('Date'[Date])))
return IF(ISFILTERED('Table'[Scheme]),_value,CALCULATE(COUNT('Table'[Scheme]),FILTER(ALL('Table'),[Start Date]<=MAX('Date'[Date])&&[End Date]>=MAX('Date'[Date]))))

then use a matrix  and the final output is shown below:

vyalanwumsft_0-1636355245416.png

Best Regards,
Community Support Team_ Yalan Wu
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

2 REPLIES 2
v-yalanwu-msft
Community Support
Community Support

Hi, @raimon ;

You could create a date table about every sunday, then create a measure to calculate the count like below:

1.create a date table.

Date = FILTER( ADDCOLUMNS( CALENDAR(DATE(2020,7,1),DATE(2020,9,1)),"weekday",WEEKDAY([Date],2)),[weekday]=7)

2.create a measure.

Measure = 
var _value=CALCULATE(COUNT('Table'[Scheme]),FILTER(ALL('Table'),[Scheme]=MAX('Table'[Scheme])&&[Start Date]<=MAX('Date'[Date])&&[End Date]>=MAX('Date'[Date])))
return IF(ISFILTERED('Table'[Scheme]),_value,CALCULATE(COUNT('Table'[Scheme]),FILTER(ALL('Table'),[Start Date]<=MAX('Date'[Date])&&[End Date]>=MAX('Date'[Date]))))

then use a matrix  and the final output is shown below:

vyalanwumsft_0-1636355245416.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

HotChilli
Super User
Super User

Disconnected date table with a measure like :

MeasureT = VAR _dt = MAX(DatesTable[Date])
RETURN
COUNTROWS(FILTER(TableG, TableG[Start Date] <= _dt && TableG[End Date] >= _dt))

Put the date field in the rows of a matrix, scheme in the columns and measure in the Values.

You might need to edit the conditions in the matrix to suit (<,<= etc).

Filter the dates table to get the rows you need (Sundays, I think).

Also Scheme 1 and 3 look wrong in the desired 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.