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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
ctashwin
Frequent Visitor

Customer Count - Start Time and end time

Hi All.

 

I trying to count number of customers at each hour. The data i have is start time and end time.

 

I used the below solution from one of the discussions and it worked. 

 

The only issue i am facing is the Count of People at Midnight. The data around midnight is coming as 0.

 

Is there a way to fix this?

 

Also, the customer Start time and end time will cross midnight.

 

Number of clients =
VAR vMinVal =
    MIN ( TimeTable[Value] )
VAR vMaxVal =
    MAX ( TimeTable[Value] )
VAR vClientEntry =
    CALCULATE (
        COUNTROWS ( ClientsTbl ),
        TimeTable[Value] <= vMinVal,
        ALL ( TimeTable )
    )
VAR vClientExit =
    CALCULATE (
        COUNTROWS ( ClientsTbl ),
        TimeTable[Value] >= vMaxVal,
        ALL ( TimeTable ),
        USERELATIONSHIP ( ClientsTbl[Exit Time], TimeTable[Value] )
    )
RETURN
    MIN ( vClientExit, vClientEntry )

 

Thanks for the Help

1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @ctashwin ,

If you need to count customers for each hour of each day, you need to create two calculated columns to format date and create the following measure:

Count = 
var _time = SELECTEDVALUE('Time'[Time])
var _count = 
CALCULATE(
    COUNTROWS('Table'),
    FILTER(
        ALL('Table'),
        _time >= 'Table'[Start] && 
        _time <= 'Table'[End] 
    )
)
return
IF(
    ISBLANK(_count),0,_count
)

count.png

Here is the sample that you can refer: sample file.pbix

 

If you just count customers for each hour instead of each hour of each day, you can refer this issue:  Counting numbers per hour between a start and end time  

 

Best Regards,
Yingjie Li

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
v-yingjl
Community Support
Community Support

Hi @ctashwin ,

If you need to count customers for each hour of each day, you need to create two calculated columns to format date and create the following measure:

Count = 
var _time = SELECTEDVALUE('Time'[Time])
var _count = 
CALCULATE(
    COUNTROWS('Table'),
    FILTER(
        ALL('Table'),
        _time >= 'Table'[Start] && 
        _time <= 'Table'[End] 
    )
)
return
IF(
    ISBLANK(_count),0,_count
)

count.png

Here is the sample that you can refer: sample file.pbix

 

If you just count customers for each hour instead of each hour of each day, you can refer this issue:  Counting numbers per hour between a start and end time  

 

Best Regards,
Yingjie Li

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

Greg_Deckler
Community Champion
Community Champion

@ctashwin - This is a variation of Open Tickets: https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364#M147



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

@ctashwin ,

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

refer if this solution can help

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

 

In place of the date table, you need a time table

https://kohera.be/blog/power-bi/how-to-create-a-time-table-in-power-bi-in-a-few-simple-steps/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.

Top Solution Authors
Top Kudoed Authors