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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
A_K
Regular Visitor

Window of three minutes if multiple columns match up

Hello,

 

Hope you are well. I have a column called device id, where the same id can appears multiple times in the column. I have another column called product id, where the same id can also appear multiple times and I have a name column with 5 distinct names that can also appear multiple times within the column. Finally, I have a date and time column where there can be multiple of the same date and time rows. The thing that I want to do is filter to only include the rows where the product id is the same, the name is the same, and the date and time column is within three minutes of each other. Then I would like to count the distinct device ids within the filtered down rows. I have created a calculated column which does this task, but the runtime is very long since I have lots of data. I will include my dax for that calculated column below. Is there a way to optimize this or do a different methods so that it will not take so long to process? Thanks

 

Dax Code: 

DistinctDeviceCountFilter = 

var currentProduct = table[productId]

var currentName = table[name]

var currentTime = table[time]
return
Calculate(DISTINCTCOUNT(table[deviceId]), All(table), table[productId] = currentProduct && table[name] = currentName && ABS(table[time] -currentTime)<= TIME(0,3,0))

2 REPLIES 2
Anonymous
Not applicable

Hi  @A_K ,

 

You can try the following dax:

DistinctDeviceCountFilter =
VAR currentTime = 'Table'[time]
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[deviceId] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[productId], 'Table'[name] ),
            ABS ( 'Table'[time] - currentTime )
                <= TIME ( 0, 3, 0 )
        )
    )

Refer to :

ALLEXCEPT function (DAX) - DAX | Microsoft Learn

 

Best Regards,

Liu Yang

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

Thanks so much for your time in answering my question, however I am still having to wait like an hour for the calculated column to finish running. I am dealing with 2 million lines of data. Could there be another approcah this?

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.