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
Rvn86
Helper I
Helper I

Count date previous date rows based on slicer selection

Hi,

 

I want to count the number of date rows based on a date chosen from a slicer. 

 

I have the following columns:

 

Startdate

End date

 

I want to count every date with a start date if the end date is smaller than the chosen date. 

 

Example: 

 

Capture.JPG

 

With the example above, I want for example to choose the date "01.02.2015", which should give me 3 as the result from the count. 

 

Any ideas? I have tried several DAX formulas, but cannot get it working with slicers. 

 

Thank you 🙂 

1 ACCEPTED SOLUTION

Hi @Rvn86,

You can try the following steps to check.

1. Create a new table including the slicer field, and get the selected value in new table. More details, please review this thread

2. Create a card visual to display your measure value, so you can debug it step by step.

Best Regards,
Angelia

View solution in original post

7 REPLIES 7
Greg_Deckler
Super User
Super User

I might be missing something but I do not understand how that chosen date results in a count of 3. The only earlier date would be the 2014 end date and all of the other end dates are later and total a count of 4...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

I was poorly explained from me, but in the example above the first row has an end date in 2014. The last row has a start date in 2016, so by that you will get the total count of 3. 

 

So there are two variables to consider: If the start date is at a date below the chosen date, and if the end date is at a later date than the chosen date. 

 

Sorry for the bad explanation in the first post, and thank you for your reply. 

 

Any tips? 🙂 

Hi @Rvn86,

First, please create a measure to get the value selected in slicer.

selectedDate = MAXX(ALLSELECTED('Date'),'Date'[Date])


Second, please create a measure to get expected result.

result = CALCULATE(COUNTROWS(Example),FILTER(Example,Example[End date]>='Date'[selectedDate]&&Example[Start date]<='Date'[selectedDate]))


1.PNG
Please feel free if you have any question.

Best Regards,
Angelia

Hi @v-huizhn-msft

 

Thank you very much. 

 

I have made your measures, but the only thing I cannot get working is to get the "result" to react with slicer selections. 

 

My slicer is from a separate date table with a relationship to the table with the data. Anything I am missing?

 

Thank you:)

 

//Rvn

Hi @Rvn86,

For my example, the slicer is also from a separate table. Please check if slicer effect your report by clicking "Edit interactions" under Fomant on home page. Please see the following screenshot, you should select the funnel button rether than the circle button.

1.PNG

Best Regards,
Angelia

Thanks again, @v-huizhn-msft 🙂

 

Yes, I know about this option, but it is not the interaction itself. When I choose a date, the formula does not consider the chosen date. It only counts when I choose days with data in it. 

 

I think it has to do with the date table and the relation between my data and the date table. 

 

I will work on this later this week, and follow up with more questions if I do not solve it.

 

Thank you very much for your willingness to reply. I really appreciate it. 

Hi @Rvn86,

You can try the following steps to check.

1. Create a new table including the slicer field, and get the selected value in new table. More details, please review this thread

2. Create a card visual to display your measure value, so you can debug it step by step.

Best Regards,
Angelia

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.