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
Anonymous
Not applicable

Measure overlapping date periods from table and date slicer

Hello everybody,

 

I am quite new to Power BI and try to solve a task, that I think should be rather easy, however I cannot fiure it out.

 

In my tabel are two columns like start_date and end_date. Now I want to apply something like a date slicer to filter the data, preferably slicing monthly periods.

What I want to get is the number of rows in my table, that are "active" during the slicer-period, that is, if the period from start_date to end_date is overlapping with the current month from the date slicer (it might also contain the whole month).

 

Does someone know how to solve this?

I would very much appreciate any help!

 

 

1 ACCEPTED SOLUTION
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You may create calendar table without creating relationship with your data table, then add the date of calendar table to the slicer visual to filter data.

Calendar= CALENDARAUTO()

 

Then you can create measure like DAX below.

 

CountRows=

Var SlicerDate=SELECTEDVALUE(Calendar[Date])

Return

CALCULATE(COUNTROWS('Table'),FILTER(ALLSELECTED('Table'),'Table'[start_date ]<=SlicerDate&&'Table'[end_date]>=SlicerDate))

Best Regards,

Amy 

 

Community Support Team _ Amy

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

5 REPLIES 5
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You may create calendar table without creating relationship with your data table, then add the date of calendar table to the slicer visual to filter data.

Calendar= CALENDARAUTO()

 

Then you can create measure like DAX below.

 

CountRows=

Var SlicerDate=SELECTEDVALUE(Calendar[Date])

Return

CALCULATE(COUNTROWS('Table'),FILTER(ALLSELECTED('Table'),'Table'[start_date ]<=SlicerDate&&'Table'[end_date]>=SlicerDate))

Best Regards,

Amy 

 

Community Support Team _ Amy

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

Anonymous
Not applicable

Hi @v-xicai 

 

that is exactly what I was looking for! Thank you very much!

ibarrau
Super User
Super User

Hey, assuming you have a column that will tell you if the row is "active" then you just need to create the measure. Check this example:

https://docs.microsoft.com/en-us/power-bi/desktop-tutorial-create-measures#create-a-measure

 

Regards,


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

Happy to help!

LaDataWeb Blog

ibarrau
Super User
Super User

Hi. First let's go with slicers. If you have two columns "From - To" you can add the StartDate as a individual slicer type "After...". Then add other individual filter with EndDate as type "Before...". There you have your range date filtering with dates.

If you want the count of the rows you need to build a DAX Measure like this:

MeasureCount =
CALCULATE (
    COUNTROWS(Table),
    Table[Column] = "Active"
)

This new measure field will only show the rows with Active in that column. The value of the dates will change with the slicers filtering this measure too.

 

Hope this helps,


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

Happy to help!

LaDataWeb Blog

Anonymous
Not applicable

Hi @ibarrau , thanks for your reply!

 

I still don't understand how to obtain this Column, with "Active" entries. Is there a way to create a column in dependent on the slicer date?

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.