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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
krzysj13
Regular Visitor

Values between 2 dates

Hello,

I'm looking the way to make new column in left table, with value from right column 'AlarmID', if its between 2 dates - LOCALTIME and Previous. Thanks alot in advance for help.

krzysj13_0-1598616676733.png

 

 

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@krzysj13, try this calculated column in the left table:

 

Alarm ID =
VAR vAlarms =
    FILTER (
        Alarms,
        Alarms[Start Time] > Main[Previous]
            && Alarms[Start Time] <= Main[Local Time]
    )
VAR vResult =
    MAXX ( vAlarms, Alarms[Alarm ID] )
RETURN
    vResult

 

Left table: Main

Right table: Alarms





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

Proud to be a Super User!




View solution in original post

4 REPLIES 4
v-alq-msft
Community Support
Community Support

Hi, @krzysj13 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table1:

d1.png

 

Table2:

d2.png

 

You may create a measure or a calculated column as below.

Measure:

Measure = 
CALCULATE(
    MAX(Table2[AlarmId]),
    FILTER(
        ALL(Table2),
        [StartTime]>=SELECTEDVALUE(Table1[Pervious])&&
        [StartTime]<=SELECTEDVALUE(Table1[Local Time])
    )
)

 

Calculated column:

Column = 
CALCULATE(
    MAX(Table2[AlarmId]),
    FILTER(
        ALL(Table2),
        [StartTime]>=EARLIER(Table1[Pervious])&&
        [StartTime]<=EARLIER(Table1[Local Time])
    )
)

 

Result:

d3.png

 

Best Regards

Allan

 

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

DataInsights
Super User
Super User

@krzysj13, try this calculated column in the left table:

 

Alarm ID =
VAR vAlarms =
    FILTER (
        Alarms,
        Alarms[Start Time] > Main[Previous]
            && Alarms[Start Time] <= Main[Local Time]
    )
VAR vResult =
    MAXX ( vAlarms, Alarms[Alarm ID] )
RETURN
    vResult

 

Left table: Main

Right table: Alarms





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

Proud to be a Super User!




Hey, thanks for the answer, but I have one more question, what if I have 2 alarms in 1 period of time?

Hi, @krzysj13 

 

It depends on the expected result. You can choose to calculate the  aggregation of the multiple alarms for a specific period. In my dax provided above, I calculated the maximum of alarms for a period. If you want to use other aggregations, you may modify it as what you need.

 

Best Regards

Allan

 

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

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.