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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.