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
todor-dk
New Member

Reporting based on Interval of two Date

Let's say we have a table with students at a school. It contains two columns, Start and End, indicating when the student started at the school and when he ended attending the school.

 

StartEndGender
2015-09-01  2020-05-26  Male
2016-08-25  2018-06-02  Female
2018-10-22   Female

 

This is obviously a simplified example, but my challenge is:

  • I want a graph that tells me the number of male/female students (absolute or relateive)
  • Distributed by year, with the possibility to drill-down the quarter, month or day levels.

In the above example, the resulting data should look something like, preferably represented by a bar chart and the option to drill down the date dimension:

 20152016201720182019202020212022
Female 1121111
Male11111   

 

PS: I am aware that I can create a fake end column to simplify calculations, in the form of: CalculatedEnd = IF(ISBLANK(Table[End]), NOW(), Table[End])

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @todor-dk ,

 

Try to create a measure like below:

ActiveStudents = CALCULATE(COUNTx(FILTER(Students, Students[Start] <= MAX('Dates'[Date]) && (Students[End] >= MIN('Dates'[Date])||ISBLANK(Students[End]) )), Students[Gender]), CROSSFILTER(Students[Start],'Dates'[Date],None))

Vlianlmsft_0-1641796485255.png

 


Best Regards,
Liang
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-lianl-msft
Community Support
Community Support

Hi @todor-dk ,

 

Try to create a measure like below:

ActiveStudents = CALCULATE(COUNTx(FILTER(Students, Students[Start] <= MAX('Dates'[Date]) && (Students[End] >= MIN('Dates'[Date])||ISBLANK(Students[End]) )), Students[Gender]), CROSSFILTER(Students[Start],'Dates'[Date],None))

Vlianlmsft_0-1641796485255.png

 


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

Hi,

 

I understand the general idea that a calendar table is needed and that a measure is used to calculate whatever is needed.

 

However, I have some issues understanding where to create the measure.

 

If we extend my example from above, I've create a table named Dates, which has one column Date one record per day in the time interval of interest.

 

I've create relations between the Start and End and Dates[Date], both are inactive.

 

Then, I've create a measure on the Dates table called ActiveStudents. It looks like this:

ActiveStudents = CALCULATE(COUNTx(FILTER(Students, Students[Start] <= MAX('Dates'[Date]) && Students[End] >= MIN('Dates'[Date]) ), Students[id]), CROSSFILTER(Students[Start],'Dates'[Date],None))

I must admit, I do not fully understand what this does. I understand the inner part, the COUNT and FILTER, but not CALCULATE and CROSSFILTER.

 

If I display Dates as a table, I get a date and the number of active students for that date. This also works if I display the dates aggregated at the month, quarter or year level.

 

But what I need is to be able to do more fancy statistics on the Studen table, for example total number of students, by gender or other colmns that exists in my real scenario. My suspicion is that the measure is not defined the correct place. Can you pls. comment.

 

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.