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
arhomberg
Helper I
Helper I

Summarize Table by Fields and Implementing Calculations

Hello everyone,

 

I am currently working to figure out the best way to combine and summarize some time series data I have. We are currently tracking quiz scores and would like to eventually see an indicator that shows how the average quiz scores have changed from the previous month for each course. What I currently am trying to figure out is how I can organize the data in a way to show the current average quiz score for each course and the previous months quiz score. I have a list of all the quizzes taken with the course name, the percent correct, and the start and end time of the quiz.

 

The data currently looks something like this:

arhomberg_0-1631200153970.png

Each instance in the table is a quiz taken.

 

 

What I would like to do is to create a new table that summarizes the results to look something like this for each course:

arhomberg_1-1631200153972.png

And so on for each course.

 

Steps to take:

  1. Group by the course name
  2. Find the current avg quiz score for that course
  3. Find the previous months average quiz score for that course
  4. Add a calculated column = (cur month avg – pre month avg) / pre month avg

Any advice on how to accomplish these first three steps would be greatly appreciated, thanks!

1 ACCEPTED SOLUTION

Hi @arhomberg ,

 

Sorry about my mistake. DATEADD needs to put the date column into the visual to work.

 

I made a simple example. I used the simplest function to filter this month and last month. Please check the screenshots and attachments.

Current Avg = CALCULATE(AVERAGE('Table'[Percent_Correct]),FILTER('Calendar',YEAR([Date])=YEAR(TODAY())&&MONTH([Date])=MONTH(TODAY())))
Prev Month Avg = CALCULATE(AVERAGE('Table'[Percent_Correct]),FILTER('Calendar',YEAR([Date])=YEAR(TODAY())&&MONTH([Date])=MONTH(TODAY())-1))
Percent change = DIVIDE([Current Avg]-[Prev Month Avg],[Prev Month Avg])

8.png10.png

 

Hope to help you. Sorry again.

 

 

Best Regards,

Stephen Tao

 

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

8 REPLIES 8
v-stephen-msft
Community Support
Community Support

Hi @arhomberg ,

 

Solving with DAX will be relatively simple.

1.Create a calendar table, and create relationship between it and the fact table

2.Current Avg=CALCULATE(AVERAGE(Table[Percent_Correct]),DATEADD('Calendar'[Date],0,MONTH))

Prev Month Avg=CALCULATE(AVERAGE(Table[Percent_Correct]),DATEADD('Calendar'[Date],-1,MONTH))

Percent change=DIVIDE([Current Avg]-[Prev Month Avg],[Prev Month Avg])

 

 

Best Regards,

Stephen Tao

 

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

@v-stephen-msft Thanks so much for this!

 

A quick question to clarify, what exactly should I be putting into the Calendar table? Would this be all the dates which the quizes exist, or just the current date? Sorry for the ignorance, but I am new to DAX. Can I also assume that the formulas you provided above are measures?

 

Thanks again!

Hi @arhomberg ,

 

You can fill in the date manually, or you can refer to a date that exists in an existing table.

You can create a calendar table like

Table 2 = CALENDAR(DATE(2021,1,1),DATE(2021,12,31))

Or

Table 2 = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

 

DAX: CALENDAR function

Also there‘s a function called CALENDARAUTO you can use.

 

Best Regards,

Stephen Tao

 

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

 

@v-stephen-msft Thanks for this! 

 

I was using the CALENDARAUTO() function, but just wan't to confirm this was what I should have been using. I am experiencing an issue when trying to implement your initial advice from above. When I create the Calendar table, add a relationship to the fact table, and create the measures, the table appears blank. 

 

arhomberg_0-1632144740639.png

arhomberg_1-1632144760446.png

 

When I delete the relationship and let the tables standalone, the table loads the information in the proper format, but the calculation for the previous month is not coming through correctly (even if I trouble shoot and try -6 months, it stays the same).

 

arhomberg_2-1632144834918.pngarhomberg_3-1632144860570.png

 

I am pretty sure I followed your directions and entered the measures correctly:

 

arhomberg_4-1632144933574.png


arhomberg_5-1632144946148.png

 

arhomberg_6-1632144968739.png

 

Any advice on why these calculations might not be working as expected would be wonderful.

 

Thank you!

Hi @arhomberg ,

 

Sorry about my mistake. DATEADD needs to put the date column into the visual to work.

 

I made a simple example. I used the simplest function to filter this month and last month. Please check the screenshots and attachments.

Current Avg = CALCULATE(AVERAGE('Table'[Percent_Correct]),FILTER('Calendar',YEAR([Date])=YEAR(TODAY())&&MONTH([Date])=MONTH(TODAY())))
Prev Month Avg = CALCULATE(AVERAGE('Table'[Percent_Correct]),FILTER('Calendar',YEAR([Date])=YEAR(TODAY())&&MONTH([Date])=MONTH(TODAY())-1))
Percent change = DIVIDE([Current Avg]-[Prev Month Avg],[Prev Month Avg])

8.png10.png

 

Hope to help you. Sorry again.

 

 

Best Regards,

Stephen Tao

 

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

@v-stephen-msft This is great, thanks for this!

Vera_33
Resident Rockstar
Resident Rockstar

Hi @arhomberg 

 

Where is your previous month data, in the same table? You can add a Month column, then group by course name and month, so you can get the avg for each month

Hello @Vera_33 

 

Thanks for the advice! Since the data is a list of all the quiz scores, the 'previous month' data is all in the same table, it would just be found by taking the current average for -30 days (or -1 month). I could do as you suggest and create a month column, group by the course name and month to find teh current averages, but would there be a way then add the calculation for the average of the previous month as well?

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.

Top Solution Authors
Top Kudoed Authors