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
nunogand
New Member

How to get daily averages grouped by month

So, I'm a beginner in PowerBi and although I've managed to find my way around Excel in PowerBi I'm still having some difficulties.

 

Right now I'm having a lot of trouble getting something that seems very simple but really shouldn't be. My data table has several columns but the relevant ones are the ones I show below.

 

Date  category    events  
01/01/2023 a2
01/01/2023 a1
01/01/2023  b1
01/01/2023 c3
02/01/2023 a1
02/01/2023 b1
02/01/2023 b2
03/01/2023 a2
 …
31/12/2024 d1

 

Throughout the year and for each day, various events have been recorded in different categories; sometimes the same event appears several times on the same day, either because it has a different quantity or because it is repeated on the same day.

 

What I want is to see the daily average for each month and I'm not managing to do that. I tried something very simple with a quick measure but the value I get is "strange": it's not the monthly, weekly or daily average. It's a number that comes from I'm not sure where (in Excel I can do this operation).

 

Basically what I want is the sum of all the events that occur in the month divided by the number of active days in the month and to be able to show this in a visualization - and in this visualization I can use the visualization filters to show only one or two categories. I can't use COUNTROWS to calculate the days because the same day is often repeated. In my head it sounds very simple but I'm missing a lot of DAX.

 

Any help or at least could you point me in the correct track?

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

Try this approach

  1. Ceate a Calendar Table with calculated column formulas for year, Month name and Month number.  Sort the Month name by the Month number
  2. Create a relationship (many to One and Single) from the Date column of your Data Table to the Date column of the Calendar Table
  3. To your Table visual, drag Year and Month from the Calendar Table
  4. Write these measures

E = sum(Data[events])

Days in month = countrows(Calendar)

Measure = divide([E],[Days in month])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

Try this approach

  1. Ceate a Calendar Table with calculated column formulas for year, Month name and Month number.  Sort the Month name by the Month number
  2. Create a relationship (many to One and Single) from the Date column of your Data Table to the Date column of the Calendar Table
  3. To your Table visual, drag Year and Month from the Calendar Table
  4. Write these measures

E = sum(Data[events])

Days in month = countrows(Calendar)

Measure = divide([E],[Days in month])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Actually, there was an error:

I can't just use Days in month = countrows(Calendar) because some of my calendar days don't have any data on them. What I did instead (and solved the problem) was using DISTINCTCOUNT('Data'[Date]). That way I counted only the individual days with associated data.

 

That did the trick.

 

Thanks.

Ashish_Mathur
Super User
Super User

Hi,

Try this approach

  1. Ceate a Calendar Table with calculated column formulas for year, Month name and Month number.  Sort the Month name by the Month number
  2. Create a relationship (many to One and Single) from the Date column of your Data Table to the Date column of the Calendar Table
  3. To your Table visual, drag Year and Month from the Calendar Table
  4. Write these measures

E = sum(Data[events])

Days in month = countrows(Calendar)

Measure = divide([E],[Days in month])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Fabric Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.