cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sunlung
Frequent Visitor

Multiple DATESBETWEEN filtering

I got two tables with following data. However, ExcludeRange StartDate and EndDate are measures instead of calculated columns for reason it is derived from whatif paramter then can't be calculated column.

 

ExcludeRange

IndexPersonStartDateEndDate
1John1-Dec2-Dec
2Tom2-Dec2-Dec
3John4-Dec5-Dec
4Tom5-Dec5-Dec

 

Sales

DatePersonValue
1-DecJohn3
2-DecJohn4
3-DecJohn5
4-DecJohn2
5-DecJohn7
1-DecTom3
2-DecTom4
3-DecTom5
4-DecTom2
5-DecTom7

 

My goal is to have a measure: For each person, derive the corresponding values by Sales but exclude ExcludeRange. Result should be as following:

DateJohnTom
1-Dec 3
2-Dec  
3-Dec55
4-Dec 2
5-Dec  

 

I tried the following but not successful since datesbetween can't be used for multiple ranges. Any can help?

sumx('Person', calculate(sumx(sales, sales[value]), filter(sales, EXCEPT(sales[Date], DATESBETWEEN(sales[Date], 'ExcludeRange'[StartDate], 'ExcludeRange'[EndDate])))))
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
sunlung
Frequent Visitor

Re: Multiple DATESBETWEEN filtering

@amitchandakThanks your reply. Anyway, i can't make a reference to filter ExcludeRange by 'Sales'[person] and 'Sales'[date] as there is no relationship between the two tables. There are 'Person' & 'CalendarDates' tables which have relationship with these two tables. Finally i used Generate to build up a casterian between Sales and ExcludeRange and then do the filtering and the result seems work. As I am not quite familiar with DAX, it may not be simplied and optimized yet. Hope anyone has similar issue will find this help.

Exclude Sales = sumx('Person',         
calculate(sum(Sales[Value]), filter(generate(Sales, ExcludeRange),
            Sales[Date]>= ExcludeRange[StartDate] && Forecast[Date]<= calculate(ExcludeRange[EndDate], Allexcept(Sales, Sales[Person])) && Sales[Person] = ExcludeRange[Person]), Sales[Person] = earlier('Person'[Person])
       )
   )

 

View solution in original post

4 REPLIES 4
Super User IV
Super User IV

Re: Multiple DATESBETWEEN filtering

@sunlung in my opinion your sales tables should have person details in it, by looking at date and value, you cannot determine for which person that sales is? Am I missing something?






Did I answer your question? Mark my post as a solution.

Proud to be a Datanaut! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





sunlung
Frequent Visitor

Re: Multiple DATESBETWEEN filtering

@parry2k. Thanks your reply. Yes, you are right there is person column in sales table but there is limitation of the post size so i skipped it. I have amended the example and include the person column. Kindly see.

Super User IV
Super User IV

Re: Multiple DATESBETWEEN filtering

One of the ways is to populate the index in your sales table and use it as a filter. When the index is blank

 

Max Index= Maxx(filter(ExcludeRange,'Sales'[person]='ExcludeRange'[person] && 'Sales'[date]>='ExcludeRange'[Start date] && 'Sales'[date]<='ExcludeRange'[end date]),ExcludeRange[index]) 




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
In case it does not help, please provide additional information and mark me with @
My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP,
HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Proud to be a Super User! Linkedin


Highlighted
sunlung
Frequent Visitor

Re: Multiple DATESBETWEEN filtering

@amitchandakThanks your reply. Anyway, i can't make a reference to filter ExcludeRange by 'Sales'[person] and 'Sales'[date] as there is no relationship between the two tables. There are 'Person' & 'CalendarDates' tables which have relationship with these two tables. Finally i used Generate to build up a casterian between Sales and ExcludeRange and then do the filtering and the result seems work. As I am not quite familiar with DAX, it may not be simplied and optimized yet. Hope anyone has similar issue will find this help.

Exclude Sales = sumx('Person',         
calculate(sum(Sales[Value]), filter(generate(Sales, ExcludeRange),
            Sales[Date]>= ExcludeRange[StartDate] && Forecast[Date]<= calculate(ExcludeRange[EndDate], Allexcept(Sales, Sales[Person])) && Sales[Person] = ExcludeRange[Person]), Sales[Person] = earlier('Person'[Person])
       )
   )

 

View solution in original post

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Top Solution Authors
Top Kudoed Authors