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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
cv2qm
Helper I
Helper I

Count values between two times with 30 mins interval on X- Axis

Hi,

 

I am trying to count value between two intervals.

I wrote measure to calculate, it is working fine. But i needvalue on 30 min interval on X -axis.

If i create table in power bi, on which column i need to give relation?

 

Measure 2 =
CALCULATE (
    DISTINCTCOUNT ( 'Data table'[StudentID] ),
    FILTER (
        'Data table',
        'Data table'[BeginTime] <= MAX ( 'Data table'[BeginTime] )
            && 'Data table'[EndTime] >= MIN ( 'Data table'[EndTime] )
    )
)

 

Untitl.png

 

Can anyone help me what i need to do to get count of values based on 30 mins interval values on X-axis.

2 ACCEPTED SOLUTIONS

Hi @cv2qm ,

 

You could create a new table with the following DAX:

New Table =
GENERATESERIES (
    MIN ( 'Table'[EndTime] ),
    MAX ( 'Table'[BeginTime] ),
    TIME ( 0, 30, 0 )
)

Then you will get a time column as 30 mins interval.

2-1.PNG
Now you could use this column as your x-axis. 

Count the ID refering to your original DAX:

Count1 =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[StudentId] ),
    FILTER (
        'Table',
        'Table'[BeginTime] <= 'NewTable'[Value]
            && 'Table'[EndTime] >= 'NewTable'[Value]
    )
)

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

Hi you can adjust the measure to that it returns 0 instead of BLANK: Count1 = VAR Result = CALCULATE ( DISTINCTCOUNT ( 'Table'[StudentId] ), FILTER ( 'Table', 'Table'[BeginTime] <= 'NewTable'[Value] && 'Table'[EndTime] >= 'NewTable'[Value] ) RETURN IF ( ISBLANK ( Result ), 0 , Result )

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

7 REPLIES 7
Greg_Deckler
Super User
Super User

OK, if I am understanding you correctly, you will want to create a disconnected table using GENERATESERIES for your x-axis. You will then likely need to do something along the lines of Open Tickets. https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/td-p/409364

 

If you can provide sample source data and such, can likely be more specific. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks for quick response. 

Attached sample data. 

I am trying to get Count of students bewteen two times. 

I want to show line chart as 30 mins interval on x-axis with number of students in that 30 mins interval.

StudentIdBeginTimeEndTime
aan5tk10001100
aan5tk10001100
aan5tk10001120
aan5tk11301250
aan5tk14101510
aan5tk18151945
aan5tk18151945
aan5tk15401700
aan5tk830950
aan5tk14101530
aan5tk10001120
aca6w10001100
aca6w14101510
aca6w830950
aca6w13001400
aca6w14101530
aca6w15401700
aca6w10001100
aca6w10001120
aca6w850950
aca6w10001120
ada5tf10001100
ada5tf10001100
ada5tf10001120
ada5tf14101510
ada5tf15401700
ada5tf15401700
ada5tf11301250
ada5tf830950
ada5tf14101530
ada5tf10001120
adb3qr10001120
adb3qr830930

Hi @cv2qm ,

 

You could create a new table with the following DAX:

New Table =
GENERATESERIES (
    MIN ( 'Table'[EndTime] ),
    MAX ( 'Table'[BeginTime] ),
    TIME ( 0, 30, 0 )
)

Then you will get a time column as 30 mins interval.

2-1.PNG
Now you could use this column as your x-axis. 

Count the ID refering to your original DAX:

Count1 =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[StudentId] ),
    FILTER (
        'Table',
        'Table'[BeginTime] <= 'NewTable'[Value]
            && 'Table'[EndTime] >= 'NewTable'[Value]
    )
)

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

Hi @v-eachen-msft,

 

Thanks for Reply.

Values are looking good. 

But some timings are missing on Axis. If data don't have some timmings. Then it's not showing on Axis. 

The main purpose of chart is to see good time to schedule anything.

 

Can you guide me how can i fix this. 

Below screenshot, 16:00 to 17:30 are missing. 

 

Capture 1.PNG

Hi you can adjust the measure to that it returns 0 instead of BLANK: Count1 = VAR Result = CALCULATE ( DISTINCTCOUNT ( 'Table'[StudentId] ), FILTER ( 'Table', 'Table'[BeginTime] <= 'NewTable'[Value] && 'Table'[EndTime] >= 'NewTable'[Value] ) RETURN IF ( ISBLANK ( Result ), 0 , Result )

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries


@ImkeF  Thank You! 

It's working fine. 

Thank you 😗!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.