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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
sossie07
New Member

newbie dax question - how to count the number of rows that have the same date?

Hi all,

 

I have a newbie dax/BI question,

I have a weather station that takes the temperature every hour (approximatly). What I want to do is find the average temperature for the day.

To do this, I could sum the max temp for the day, and the min and devide by two, but this is not very accurate average, and I have the temperature taken every hour. I could add up all the temperature readings for the day, and assume there are 24 measurements, but I have noticed sometimes its out by a minute or two, so perhaps sometimes there are 23 measurements.

 

So what I would like to do is sum the temperature readings for a day, and then devide this by the count of readings for the day.

 

I have two questions around this -

1) Would it be best to make this a new column or a measure?

2) can anyone give a sample of how I might calculate this?

 

Thanks

3 ACCEPTED SOLUTIONS
ribisht17
Super User
Super User

@sossie07 

 

1. Measure -https://www.sqlbi.com/articles/calculated-columns-and-measures-in-dax/

 

2. Your measure should be  DIVIDE( SUM(Temperature), Count_Hours  )

 

where Count_Hours =CALCULATE(COUNT(Orders[Order Date]),ALLEXCEPT(Orders,Orders[Order Date]))

 

It will count the number of occurrences within a day, assuming Order Date granular level is set to a day,

 

Please post sample data to get more clarifications

Regards,

Ritesh

View solution in original post

tamerj1
Super User
Super User

Hi @sossie07 
Measure = AVERAGE ( 'Table'[Column] )

View solution in original post

v-tangjie-msft
Community Support
Community Support

Hi @sossie07 ,

 

According to your description, you want to find the average temperature for the day. Here are my steps you can follow as a solution.

 

(1)This is my test data.

vtangjiemsft_0-1663577239366.png

(2)We can create  a measure.

Average temperature = DIVIDE(CALCULATE(SUM('Table'[Temperature]),ALLEXCEPT('Table','Table'[Date])),COUNTROWS(ALLEXCEPT('Table','Table'[Date])))

(3)Then the result is as follows.

vtangjiemsft_1-1663577239371.png

 

 

If this method does not meet your needs, you can provide us with detailed input and output examples in tabular form so that we can better solve the problem for you.

 

Best Regards,

Neeko Tang

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-tangjie-msft
Community Support
Community Support

Hi @sossie07 ,

 

According to your description, you want to find the average temperature for the day. Here are my steps you can follow as a solution.

 

(1)This is my test data.

vtangjiemsft_0-1663577239366.png

(2)We can create  a measure.

Average temperature = DIVIDE(CALCULATE(SUM('Table'[Temperature]),ALLEXCEPT('Table','Table'[Date])),COUNTROWS(ALLEXCEPT('Table','Table'[Date])))

(3)Then the result is as follows.

vtangjiemsft_1-1663577239371.png

 

 

If this method does not meet your needs, you can provide us with detailed input and output examples in tabular form so that we can better solve the problem for you.

 

Best Regards,

Neeko Tang

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

 

tamerj1
Super User
Super User

Hi @sossie07 
Measure = AVERAGE ( 'Table'[Column] )

ribisht17
Super User
Super User

@sossie07 

 

1. Measure -https://www.sqlbi.com/articles/calculated-columns-and-measures-in-dax/

 

2. Your measure should be  DIVIDE( SUM(Temperature), Count_Hours  )

 

where Count_Hours =CALCULATE(COUNT(Orders[Order Date]),ALLEXCEPT(Orders,Orders[Order Date]))

 

It will count the number of occurrences within a day, assuming Order Date granular level is set to a day,

 

Please post sample data to get more clarifications

Regards,

Ritesh

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Kudoed Authors