Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Filter data based on calculation

Hi All,

I'm new to power bi, and need help with the following scenario. We are getting device data , which lists alarms with start date time and end date time. Sample data shown below, where users want to see all alarms active in a date range which they can select. 

Point IDStart date of alarm(s)Start time of alarm(s)End date of alarm(s)End time of alarm(s)Overflow Alarm Duration (Secs)
1058509430/09/202018:46:4002/10/202020:50:55745500
1058509401/10/202018:46:4002/10/202020:50:5574550
1058509402/10/202018:46:4002/10/202020:50:557455
1058509403/10/202001:18:2603/10/202014:15:1046604
1058509404/10/202009:28:0904/10/202013:36:1914890
1058509413/10/202019:50:4113/10/202020:43:103149
1058509424/10/202019:30:3925/10/202003:08:1027451

Eg. if they select date range from 02/10 - 03/10 then the top 4 records should get displayed because these alarms are active b/w 02/10 & 03/10.


I have added a date table , joined on Start date in the fact table. On adding this date in slicer only the records which are in range of date selection are displayed. So, i have also created a date table which is not joined to any table and only used to input date range. After this I created a measure to check if alarm dates are in range, and which returns 1 if true as shown below:

ShowInPeriod =
var RangeStart = MIN(DateList[Date])
var RangeEnd = MAX(DateList[Date])
var showIf =
SWITCH(
TRUE(),
(RangeStart <= MIN('EDM Overflow Data'[StartDate]) && RangeEnd >= MIN('EDM Overflow Data'[StartDate]) ) ,1,
(RangeStart <= MIN('EDM Overflow Data'[EndDate]) && RangeEnd >= MIN('EDM Overflow Data'[EndDate]) ) ,1,
(RangeStart >= MIN('EDM Overflow Data'[StartDate]) && RangeEnd <= MIN('EDM Overflow Data'[EndDate]) ) ,1
)
return showIf
 
Then I put this measure in the filter pane and set filter to 1. In doing so I'm getting error, that visual has exceeded available resources.
 
Please advise regarding this scenario.
 
Kind Regards
Anshuman

 

 

 

1 ACCEPTED SOLUTION
mwegener
Most Valuable Professional
Most Valuable Professional

Hi @Anonymous ,

 

try this.

ShowInPeriod = 
VAR RangeStart =
    MIN ( DateList[Date] )
VAR RangeEnd =
    MAX ( DateList[Date] )
VAR Alerts =
    FILTER (
        'EDM Overflow Data',
        ( RangeStart <= 'EDM Overflow Data'[Startdate]
            && RangeEnd >= 'EDM Overflow Data'[StartDate] )
            || ( RangeStart <= 'EDM Overflow Data'[EndDate]
            && RangeEnd >= 'EDM Overflow Data'[EndDate] )
            || ( RangeStart >= 'EDM Overflow Data'[StartDate]
            && RangeEnd <= 'EDM Overflow Data'[EndDate] )
    )
RETURN
    COUNTROWS ( Alerts )



Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


View solution in original post

5 REPLIES 5
mwegener
Most Valuable Professional
Most Valuable Professional

Hi @Anonymous ,

 

try this.

ShowInPeriod = 
VAR RangeStart =
    MIN ( DateList[Date] )
VAR RangeEnd =
    MAX ( DateList[Date] )
VAR Alerts =
    FILTER (
        'EDM Overflow Data',
        ( RangeStart <= 'EDM Overflow Data'[Startdate]
            && RangeEnd >= 'EDM Overflow Data'[StartDate] )
            || ( RangeStart <= 'EDM Overflow Data'[EndDate]
            && RangeEnd >= 'EDM Overflow Data'[EndDate] )
            || ( RangeStart >= 'EDM Overflow Data'[StartDate]
            && RangeEnd <= 'EDM Overflow Data'[EndDate] )
    )
RETURN
    COUNTROWS ( Alerts )



Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


Anonymous
Not applicable

Hi Marcus,

 

Thanks for your reply. The solution works better than the switch I was using. I also tweaked your expression slightly as given below, by removing the date filter from the date table which is joined to the fact. I thought with this I can get away without creating a second date list , as I have currently.

ShowInPeriod4 =
var RangeStart = MIN('Calendar'[Date])
var RangeEnd = MAX('Calendar'[Date])

VAR Alerts =
FILTER (
CALCULATETABLE('EDM Overflow Data',REMOVEFILTERS('Calendar'[Date])),
( RangeStart <= 'EDM Overflow Data'[Startdate]
&& RangeEnd >= 'EDM Overflow Data'[StartDate] )
|| ( RangeStart <= 'EDM Overflow Data'[EndDate]
&& RangeEnd >= 'EDM Overflow Data'[EndDate] )
|| ( RangeStart >= 'EDM Overflow Data'[StartDate]
&& RangeEnd <= 'EDM Overflow Data'[EndDate] )
)
RETURN
COUNTROWS ( Alerts )
 
This works similar in terms of timing with your expression, but I have to include this in the list else it works as a normal slicer would. Is there a way to keep this in the list, but hide it from view ??
mwegener
Most Valuable Professional
Most Valuable Professional

Hi @Anonymous ,

 

can you show the problem in screenshots?
It should work as a filter on the visual or not?

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


parry2k
Super User
Super User

@Anonymous try this measure and filter on 1

 

Measure = 
COUNTX ( 
    Range, 
    IF ( 
        ( Range[Start date of alarm(s)] <= MIN ( 'Calendar'[Date] ) || Range[Start date of alarm(s)] <= MAX ( 'Calendar'[Date] ) ) && 
        ( Range[End date of alarm(s)] <= MIN ( 'Calendar'[Date] ) || Range[End date of alarm(s)] <= MAX ( 'Calendar'[Date] ) ), 
        1 
    )
)

 

Follow us on LinkedIn

 

Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi Parry2k, Thanks for the update. I had to tweak the if condition a little bit, but this expression is working. Currently we have reduced the developement data, so I can't comment on performance but this is working slightly better than my switch statement. 🙂

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.