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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
rafal_walisko
Helper I
Helper I

Dax Measure to check if event happend between two datetimes.

Hello, I have one table that includes some events that happend between two datetimes (start/endtime) with corresponding device.

I have also table with logs where I've got devices and timestamp related to some actions.

Table A

IDDeviceDateStart TimeEnd Time
1A01.01.202201.01.2022 15:0001.01.2022 17:00
2B02.01.202202.01.2022 13:1002.01.2022 13:15
3C04.01.202204.01.2022 13:1004.01.2022 13:11

 

Table B

DeviceTimeAction
A01.01.2022 15:12x
B02.01.2022 13:11y
C04.01.2022 17:10z
A01.01.2022 15:15z
A01.01.2022 15:15x

 

In a result I'd like to obtain table like this, where I'will have  summary of counts of each action that was taken on device in specific date.

 

Result table

IDDayDeviceAction XAction yAction Z
101.01.2022A201
202.01.2022B010
304.01.2022C000

 

How I can obtain such measures? I know that I will need to have measure for each action, but the number of actions will be low (around 5-6).

 

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1668626445645.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

4 REPLIES 4
rafal_walisko
Helper I
Helper I

Thank you @v-yinliw-msft  @CNENFRNL 

in this example the cardinality is one to many because of only 3 examples.

How can I work with it when the first table would look like this

 

IDDeviceDateStart TimeEnd Time
1A01.01.202201.01.2022 15:0001.01.2022 17:00
2B02.01.202202.01.2022 13:1002.01.2022 13:15
3C04.01.202204.01.2022 13:1004.01.2022 13:11
4C04.01.202204.01.2022 16:1004.01.2022 16:11
5A06.01.202206.01.2022 16:1006.01.2022 16:11

CNENFRNL_0-1668734399988.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

v-yinliw-msft
Community Support
Community Support

Hi @rafal_walisko ,

 

You can try this method:

New a table:

ResultTable =
SUMMARIZE (
    'TableA',
    'TableA'[ID],
    "Day", MAX ( 'TableA'[Date].[Date] ),
    "Device", MAX ( 'TableA'[Device] ),
    "Action X",
        CALCULATE (
            COUNTROWS ( TableB ),
            FILTER (
                'TableB',
                'TableB'[Time] >= MIN ( 'TableA'[Start Time] )
                    && 'TableB'[Time] <= MAX ( 'TableA'[End Time] )
                    && 'TableB'[Action] = "x"
            )
        ),
    "Action Y",
        CALCULATE (
            COUNTROWS ( TableB ),
            FILTER (
                'TableB',
                'TableB'[Time] >= MIN ( 'TableA'[Start Time] )
                    && 'TableB'[Time] <= MAX ( 'TableA'[End Time] )
                    && 'TableB'[Action] = "y"
            )
        ),
    "Action Z",
        CALCULATE (
            COUNTROWS ( TableB ),
            FILTER (
                'TableB',
                'TableB'[Time] >= MIN ( 'TableA'[Start Time] )
                    && 'TableB'[Time] <= MAX ( 'TableA'[End Time] )
                    && 'TableB'[Action] = "z"
            )
        )
)

 

The result is :

vyinliwmsft_0-1668671388356.png

 

 

 

Here is my PBIX file.

Hope this helps you.

 

Best Regards,

Community Support Team _Yinliw

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

CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1668626445645.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.