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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
PJStevens
Advocate II
Advocate II

Help optimizing a row by row calculated column that filters on the past 30 minutes

Hello All,

 

I have spent all day today and yesterday trying to solve an issue I have with a calculated column a former colleague made. It is taking extremely long to run over data sets of 300-400k rows, and I haven't been able to solve the issue.

  var Summed = CALCULATE(
                    (SUM('Leveringszekerheid MI'[Counter Onderbreking CV]))/4,
                    FILTER(
                        ALL('Leveringszekerheid MI'),
                        'Leveringszekerheid MI'[DateTimeKey] <= CurrenDateTime && 'Leveringszekerheid MI'[DateTimeKey] > 'Leveringszekerheid MI'[DateTimeKey] - Time(0, 30, 0)
                        )
                    )
return
    IF(Summed = 1,1,0)
 
Seems to be an issue summing the values over the filtered period (datetimekey)-time(0,30,0) combined with the logic if statement. The column Counter Onderbreking CV is a simply calculated column that is counting the amount of interferences their were recorded (based on certain conditions that aren't really relevant, but they result in 1's or 0's)
 
Any tips would be greatly appreciated as I cannot seem to solve this
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @PJStevens ,

 

Maybe you can try below formula to create calculated column:

Summed Calculation = 
VAR CurrentDateTime = 'Table'[DateTimeKey]
VAR StartTime = CurrentDateTime - TIME(0, 30, 0)
VAR Summed = 
    CALCULATE(
        SUM('Table'[Counter Onderbreking CV]) / 4,
        FILTER(
            'Table',
            'Table'[DateTimeKey] <= CurrentDateTime &&
            'Table'[DateTimeKey] > StartTime
        )
    )
RETURN
    IF(Summed = 1, 1, 0)

vkongfanfmsft_0-1719222048375.png

Best Regards,
Adamk Kong

 

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

Hi @PJStevens ,

 

Maybe you can try below formula to create calculated column:

Summed Calculation = 
VAR CurrentDateTime = 'Table'[DateTimeKey]
VAR StartTime = CurrentDateTime - TIME(0, 30, 0)
VAR Summed = 
    CALCULATE(
        SUM('Table'[Counter Onderbreking CV]) / 4,
        FILTER(
            'Table',
            'Table'[DateTimeKey] <= CurrentDateTime &&
            'Table'[DateTimeKey] > StartTime
        )
    )
RETURN
    IF(Summed = 1, 1, 0)

vkongfanfmsft_0-1719222048375.png

Best Regards,
Adamk Kong

 

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

Hello,

 

Thanks for the reply. This is indeed the solution I went with, unfortunately, due to the nature of the calculation, I have decided to only apply it to the past 2 months as to not overload it.


I will mark it as solved, as this is essentially the same calculation I am using, but instead of using it on the entire data set, I only use it on the past 2 months.

 

Thanks anyways for the reply.

lbendlin
Super User
Super User

Install DAX Studio and then use it to examine the query plan and modify according to your findings.

 

No need to specify FILTER inside CALCULATE - that will be done for you automatically.

 

Consider using aggregation functions instead of CALCULATE.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.