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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
victoryamaykin
Advocate I
Advocate I

Measure to Filter out Values Based on Current Time

I'm working on an operational dashboard to show production by location.
When the executive looks at the dashboard in the early morning before store hours, I want them to see yesterday's production numbers.
After 9 am, I want them to start seeing today's production. How do I filter based on the current time? 


Here's the if statement I'm testing:

// IF the current hour is before 9 am

IF(TIME(HOUR(UTCNOW()), MINUTE(UTCNOW()), SECOND(UTCNOW())) < TIME(9,00,00),

     // THEN show yesterday's numbers

    CALCULATE(SUMX(FactTagProduction, [ValueStocked]),

        DATEADD(FactTagProduction[DateID], -1, Day)
    ),

    // ELSE show today's numbers

    CALCULATE(SUMX(FactTagProduction, [ValueStocked]),

        FactTagProduction[DateID] = TODAY()
    )
)
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @victoryamaykin ,

If I understand correctly, the issue is that you want to filter values based on current time. Please try the following methods and check if they can solve your problem:

1.Create the simple table. 

vjiewumsft_0-1703756438949.png

2.Go to the Modeling tab and click on New measure.

vjiewumsft_1-1703756454904.png

 

3.Create a measure to filter based on the current time. Enter the following DAX formula.

 

 

Measure Numbers = var _date=SELECTEDVALUE(FactTagProduction[DateID])
VAR CurrentHour = HOUR(NOW())
VAR A = YEAR(_date)
VAR B = MONTH(_date)
VAR C = DAY(_date)
VAR D =
CALCULATE(
        SUM(FactTagProduction[ValueStocked]),
        FILTER(
            'FactTagProduction',
        YEAR(TODAY() - 1) = A && MONTH(TODAY() - 1) = B && DAY(TODAY() - 1) = C
    )
)
VAR E =
CALCULATE(
        SUM(FactTagProduction[ValueStocked]),
        FILTER(
            'FactTagProduction',
        YEAR(TODAY()) = A && MONTH(TODAY()) = B && DAY(TODAY()) = C
    )
)
RETURN
IF(
    CurrentHour < 9,
    D,
    E
)

 

 

  1. Move the measure numbers to the columns.

vjiewumsft_2-1703756622157.png

 

5.The result is shown below.

vjiewumsft_4-1703756679363.png

If the above ones can’t help you get it working, could you please provide more raw data(exclude sensitive data) with Text format or screenshot to make a deep troubleshooting? It would be helpful to find out the solution.

 

Looking forward to your reply.

Best Regards,

Wisdom Wu

 

 

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @victoryamaykin ,

If I understand correctly, the issue is that you want to filter values based on current time. Please try the following methods and check if they can solve your problem:

1.Create the simple table. 

vjiewumsft_0-1703756438949.png

2.Go to the Modeling tab and click on New measure.

vjiewumsft_1-1703756454904.png

 

3.Create a measure to filter based on the current time. Enter the following DAX formula.

 

 

Measure Numbers = var _date=SELECTEDVALUE(FactTagProduction[DateID])
VAR CurrentHour = HOUR(NOW())
VAR A = YEAR(_date)
VAR B = MONTH(_date)
VAR C = DAY(_date)
VAR D =
CALCULATE(
        SUM(FactTagProduction[ValueStocked]),
        FILTER(
            'FactTagProduction',
        YEAR(TODAY() - 1) = A && MONTH(TODAY() - 1) = B && DAY(TODAY() - 1) = C
    )
)
VAR E =
CALCULATE(
        SUM(FactTagProduction[ValueStocked]),
        FILTER(
            'FactTagProduction',
        YEAR(TODAY()) = A && MONTH(TODAY()) = B && DAY(TODAY()) = C
    )
)
RETURN
IF(
    CurrentHour < 9,
    D,
    E
)

 

 

  1. Move the measure numbers to the columns.

vjiewumsft_2-1703756622157.png

 

5.The result is shown below.

vjiewumsft_4-1703756679363.png

If the above ones can’t help you get it working, could you please provide more raw data(exclude sensitive data) with Text format or screenshot to make a deep troubleshooting? It would be helpful to find out the solution.

 

Looking forward to your reply.

Best Regards,

Wisdom Wu

 

 

 

That worked very well. The only line I had to change was the CurrentHour variable to correspond to my timezone (since the Now() function appears to be UTC by default). 

Thank you for your help!



Fowmy
Super User
Super User

@victoryamaykin 

So did you test this measure ?

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Thank you for your response. The posted solution worked for me. It helped to use the FILTER instead of DATEADD. 

Helpful resources

Announcements
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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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