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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
bourne2000
Helper V
Helper V

How to calculate count in date and time column?

Hi

 

I have below Date/time column

 

Date/Time
1.1.21 1:52:10 PM
1.1.21 1:52:10 PM
1.1.21 1:52:10 PM
1.1.21 1:52:10 PM
1.1.21 1:52:10 PM
1.1.21 1:52:10 PM
1.1.21 1:52:10 PM
1.1.21 1:55:10 PM
1.1.21 1:55:10 PM
1.1.21 1:55:10 PM
1.1.21 2:00:10 PM
1.1.21 2:00:10 PM
1.1.21 2:00:10 PM
1.1.21 2:00:10 PM
1.1.21 2:00:10 PM
1.1.21 2:00:10 PM
1.1.21 2:00:10 PM
1.1.21 2:00:10 PM
2.1.21 1:00:10 PM
2.1.21 1:00:10 PM
2.1.21 1:00:10 PM
2.1.21 1:00:10 PM
2.1.21 2:00:10 PM
2.1.21 3:00:10 PM

 

I need to count, how many records are present on each date. Need output as expected

Date/TimeCount
1.1.2118
2.1.216

 

 

My data is huge and it's direct query. Can anyone advise how to calculate the count?

1 ACCEPTED SOLUTION

That's really odd! 

 

Try creating the calculated column as follows:

DateColumn = INT ( TestTable[DateTimeColumn] )

 

It will default to a "Whole Number" data type. Set it back to "Date" and then use it in your visual it then all seems to work:

 

bcdobbs_0-1641158375732.png

 

 I think it must be something to do with how direct query is folding back to source. Will look into it some more as don't have a good answer at the moment.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

View solution in original post

10 REPLIES 10
bcdobbs
Super User
Super User

I think if you create a calculated column that's directly equal to your existing one.

 

eg New Column = TableName[Original Column]

you can set it's data type to "date".

 

At that point COUNTROWS should do the job.

 

(Not by a computer so think you need the calculated column step because it's direct query but might work without it)



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

@bcdobbs I tried it's not working

 

bourne2000_0-1641155947218.png

 

It's coming individual

 

Can you please advise

I think you've formatted it as date rather than actually changing the data type. Same modelling tab but far left.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

Not sure whether I am doing correct

 

bourne2000_0-1641156940980.png

 

bourne2000_1-1641156954233.png

 

Please advise

That looks like it should now be correct. Will grab my laptop and have a go. Fairly sure that should have worked. Will get back to you asap



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

That's really odd! 

 

Try creating the calculated column as follows:

DateColumn = INT ( TestTable[DateTimeColumn] )

 

It will default to a "Whole Number" data type. Set it back to "Date" and then use it in your visual it then all seems to work:

 

bcdobbs_0-1641158375732.png

 

 I think it must be something to do with how direct query is folding back to source. Will look into it some more as don't have a good answer at the moment.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

Doing it my original way the conversion to date wasn't being folded back to source (you can see the SQL query if you go to View >> Performance Analyser.

 

My INT suggestion will work but a better way would be to change the datatype in Power Query:

bcdobbs_1-1641159047886.png

 



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

@bcdobbs  my data is big, I am using a direct query. Unable to change in Power Query. Any other method?

I was testing with a direct query connection. Direct query runs through an power query layer only certain transforms are possible but that one works.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

thanks. I am attaching the sample pbix file

 

https://we.tl/t-IyAK3QmTgW

 

Thanks for your help

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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