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
cmaloyb
Helper II
Helper II

Line Graph with Multiple Months and Averages

Hi there,

 

I am fairly new to Power BI and need help with creating a trend line/line graph from my data.

 

My first table, Monthly Turn-In Table tracks when students A through G turn in a monthly assignment. The fields in this table are Unique ID which is self explanatory, Student (A through G), associted ID, and date on when assignment was turned in. 

 

The second table, ActiveGrade, gives a date (or null) for students that have been in the program long enough that their grade will begin to count as credit. For example, Student C has been turning in their monthly assingment since they began the program but come 3/1/2019, the assignment will begin to count as credit.

 

After putting it into Power BI, I have edited the query to have each month as its own field to count if a student has submitted their monthly assingment. I have also added a field for each month to give a value for those students that are active. Students without ActiveGradeDates were active previous to the beginning of the data.

 

I merged the ActiveGrade query with the Monthly Turn-in along with grouping and pivoting to achieve the above query. 

Monthly Turn-In Table Part 1Monthly Turn-In Table Part 1Monthly Turn-In Table Part 2Monthly Turn-In Table Part 2

 

I can not seem to figure out how to have all 12 months on the x-axis while having a single line graph to connect the 12 different points from the calculation (# of submissions in month)/(# of active students in same month).

 

I've tried many different approaches and have yet to figure it out.

 

P.S. I do need the query how it is for other graphing purposes in my report. Sorry for the long message!

 

Thanks!

Connor

 

1 ACCEPTED SOLUTION

Hi @cmaloyb ,

Please try to update the formula of measure as below:

NumberofsubA = VAR a=MAX('Table 1'[Turn-in Date (Month)])
VAR b=DIVIDE(CALCULATE(DISTINCTCOUNT('Table 1'[Student ID])),
COUNTBLANK('Table 2'[Program Start Date])+CALCULATE(COUNT('Table 2'[Student ID]),FILTER('Table 2',NOT(ISBLANK('Table 2'[Program Start Date]))&&'Table 2'[Program Start Date]<=a)),0)
return b

Here updated the formula of calculating the number of active students:

1. Calculate the number of program start date which is blank     

COUNTBLANK('Table 2'[Program Start Date])

2. Calculate the number of program start data which is less than assignment submit date

CALCULATE(COUNT('Table 2'[Student ID]),FILTER('Table 2',NOT(ISBLANK('Table 2'[Program Start Date]))&&'Table 2'[Program Start Date]<=a)

3. Add both to get active student numbers

Best Regards

Rena

Community Support Team _ Rena
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

13 REPLIES 13
v-yiruan-msft
Community Support
Community Support

Hi @cmaloyb ,

If I understand correctly , you have two tables : Table 1 and Table 2 . Table 1 contains the student ID and the date which the student submit assignment , and Table 2 contains the student and the date the program was started . It looks like as below:

tt.JPG

Your expected result is to get one line chart as below screenshot with data in X axis and the percentage of active students number and the submitted assignments display in "Values" field?
line chart.JPG

 

Whether the above understanding is correct? If no, please correct me. And could you please provide some sample data (exclude sensitive data) from this 2 tables with text?

 

Best Regards

Rena

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

Hi @v-yiruan-msft, that is correct.

 

Table 1 will have multiple submissions from more than one student whereas Table 2 will only have the student and their respective program start date once (one-to-many relationship).  I will provide some example data (non-sensitive) of both Table 1 and 2.

 

Table 1:

Unique IDStudentStudent IDTurn-in Date (Month)
T0001AS00011/3/2019
T0002BS00021/3/2019
T0003CS00031/2/2019
T0004DS00041/6/2019
T0005ES00051/23/2019
T0006FS00061/15/2019
T0007GS00071/9/2019
T0008AS00012/16/2019
T0009DS00042/14/2019
T0010ES00052/28/2019
T0011BS00022/1/2019
T0012GS00072/2/2019
T0013AS00013/1/2019
T0014BS00023/1/2019
T0015CS00033/2/2019
T0016FS00063/3/2019
T0017AS00014/1/2019
T0018BS00024/16/2019
T0019DS00044/20/2019
T0020ES00054/20/2019
T0021FS00064/21/2019
T0022GS00074/22/2019
T0023AS00015/1/2019
T0024BS00025/2/2019
T0025CS00035/3/2019
T0026DS00045/4/2019
T0027ES00055/5/2019
T0028FS00065/6/2019
T0029GS00075/7/2019
T0030BS00026/24/2019
T0031CS00036/28/2019
T0032ES00056/29/2019
T0033GS00076/30/2019
T0034AS00017/12/2019
T0035CS00037/22/2019
T0036GS00077/29/2019
T0037AS00018/12/2019
T0038BS00028/13/2019
T0039CS00038/14/2019
T0040DS00048/15/2019
T0041FS0006

8/16/2019

Extends to December but didn't seem necessary to provide submissions for all months. 

 

Table 2: (Blanks represent previous start dates prior to 2019)

Student IDProgram Start Date
S0001 
S0002 
S00033/1/2019
S0004 
S00054/1/2019
S0006 
S000710/1/2019

As for the line chart, you are absolutely correct. I would like to display each month in the x-axis and in the "Values" field I would like to have the average of submissions per active students on a monthly basis. 

 

For example, in January, I would like to display the value: (7 Submissions)/(4 Active Students) = 1.75 or 175% 

So a value for each month on one continuous line graph.

 

Note: I do need the query as shown above for other graphing purposes.

 

Thank you for your response!

 

R/

Connor

Hello @cmaloyb,

You can create a measure as shown below:

NumberofsubA = VAR a=MAX('Table 1'[Turn-in Date (Month)]) 
VAR b=CALCULATE(DISTINCTCOUNT('Table 1'[Student ID]))/
CALCULATE(DISTINCTCOUNT('Table 2'[Student ID]),FILTER('Table 2',ISBLANK('Table 2'[Program Start Date])|| (YEAR('Table 2'[Program Start Date])=YEAR(A)&&MONTH('Table 2'[Program Start Date])<=MONTH(a)))) 
return b

line chart.JPG

Best regards

Rena

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

@v-yiruan-msft ,

 

Thank you very much, that seems to work. I did find one issue through extending the example. When the year ends (2019 in this case) and the students begin turning in their monthly assignments the following year (2020), those students with Program Start Dates in 2019 (S0003, S0005, S0007) are no longer counted as active students. 

 

Would you mind explaining what dax in the measure means to help me work this out?

 

Connor

Hi @cmaloyb ,

Where did the dates you put on line chart Axis come from? Is it from a calendar table? Or from the field Turn-in Date (Month) in Table 1

Best Regards

Rena

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

Hi @v-yiruan-msft

 

The dates on the Axis came from the field Turn-In Date (Month) in Table 1.

 

R/

Connor

Hi @cmaloyb ,

Please update the formula of measure as below:

NumberofsubA = VAR a=MAX('Table 1'[Turn-in Date (Month)])
VAR b=CALCULATE(DISTINCTCOUNT('Table 1'[Student ID]))/
CALCULATE(DISTINCTCOUNT('Table 2'[Student ID]),FILTER('Table 2',ISBLANK('Table 2'[Program Start Date])|| (YEAR('Table 2'[Program Start Date])<=YEAR(A)&&MONTH('Table 2'[Program Start Date])<=MONTH(a))))
return b

And the meaning of the formula as follow:

1. Get the current Turn-in Date    

VAR a=MAX('Table 1'[Turn-in Date (Month)])

2. Count the number of the submission

CALCULATE(DISTINCTCOUNT('Table 1'[Student ID]))

3. Count the number of the active student

  1) Get the records which the program start date is blank or less than assignment turn in date 

FILTER('Table 2',ISBLANK('Table 2'[Program Start Date])|| (YEAR('Table 2'[Program Start Date])<=YEAR(A)&&MONTH('Table 2'[Program Start Date])<=MONTH(a)))

   2) Count of the number of the students who satisfy the above conditions

DISTINCTCOUNT('Table 2'[Student ID])

In addition, please find the details of the functions used in formula in following documentations:

https://docs.microsoft.com/en-us/dax/distinctcount-function-dax

https://docs.microsoft.com/en-us/dax/filter-function-dax

Best Regards

Rena

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

Hi @v-yiruan-msft,

 

So I added I changed a Program Start Date in Table 2 to test the measure, however, it still does not include those dates that were passed in the previous year. 

 

New Table 2:

 

Student IDProgram Start Date
S0001 
S0002 
S00033/1/2019
S0004 
S00054/1/2019
S00061/2/2020
S0007

10/1/2019

 

I added more submissions onto Table 1 as well for January 2020 to test the measure.

 

T0061BS00021/3/2020
T0062CS00031/18/2020
T0063DS00041/19/2020
T00064GS00071/20/2020

 

With the measure NumberofsubA put into a Line Graph by Month, January 2020 has NumberofsubA = 1.00

 

Given the 4 submissions in January 2020 with the 3 blank Program Start Dates & 1  Jan. 2020 Program Start Date (4 Program Start Dates), this would be: 4 Submissions/4 Program Start Dates = 1.00. 

 

We are still missing those 3 Program Start Dates from the previous year in 2019 (S0003, S0005 & S0007).

 

I have tried modifying the given measure, however I'm usually left with an error or a calculation that is very far from correct.

 

Any ideas? 

 

I would like to thank you so much for your help so far! It has been wonderful learning!

 

R/

Connor

Hi @cmaloyb ,

Please try to update the formula of measure as below:

NumberofsubA = VAR a=MAX('Table 1'[Turn-in Date (Month)])
VAR b=DIVIDE(CALCULATE(DISTINCTCOUNT('Table 1'[Student ID])),
COUNTBLANK('Table 2'[Program Start Date])+CALCULATE(COUNT('Table 2'[Student ID]),FILTER('Table 2',NOT(ISBLANK('Table 2'[Program Start Date]))&&'Table 2'[Program Start Date]<=a)),0)
return b

Here updated the formula of calculating the number of active students:

1. Calculate the number of program start date which is blank     

COUNTBLANK('Table 2'[Program Start Date])

2. Calculate the number of program start data which is less than assignment submit date

CALCULATE(COUNT('Table 2'[Student ID]),FILTER('Table 2',NOT(ISBLANK('Table 2'[Program Start Date]))&&'Table 2'[Program Start Date]<=a)

3. Add both to get active student numbers

Best Regards

Rena

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

@v-yiruan-msft ,

 

I've run into a requirement change where those who were submitting their monthly assignments will not count in the numerator until their program start date is met.

 

How do I include this filter in the numerator? I tried using the filtering method used in the denominator, however it does not return the correct results.

 

R/

Connor

@v-yiruan-msft that seems to work! 

 

Thank you so much for your help!

 

R/

Connor

Hi @v-yiruan-msft,

 

So I added I changed a Program Start Date in Table 2 to test the measure, however, it still does not include those dates that were passed in the previous year. 

 

New Table 2:

 

Student IDProgram Start Date
S0001 
S0002 
S00033/1/2019
S0004 
S00054/1/2019
S00061/2/2020
S0007

10/1/2019

 

I added more submissions onto Table 1 as well for January 2020 to test the measure.

 

T0061BS00021/3/2020
T0062CS00031/18/2020
T0063DS00041/19/2020
T00064GS00071/20/2020

 

With the measure NumberofsubA put into a Line Graph by Month, January 2020 has NumberofsubA = 1.00

 

Given the 4 submissions in January 2020 with the 3 blank Program Start Dates & 1  Jan. 2020 Program Start Date (4 Program Start Dates), this would be: 4 Submissions/4 Program Start Dates = 1.00. 

 

We are still missing those 3 Program Start Dates from the previous year in 2019 (S0003, S0005 & S0007).

 

I have tried modifying the given measure, however I'm usually left with an error or a calculation that is very far from correct.

 

Any ideas? 

 

I would like to thank you so much for your help so far! It has been wonderful learning!

 

R/

Connor

Hi @cmaloyb ,

You can create one measure as below:

NumberofsubA = VAR a=MAX('Table 1'[Turn-in Date (Month)]) 
VAR b=CALCULATE(DISTINCTCOUNT('Table 1'[Student ID]))/
CALCULATE(DISTINCTCOUNT('Table 2'[Student ID]),FILTER('Table 2',ISBLANK('Table 2'[Program Start Date])||(YEAR('Table 2'[Program Start Date])=YEAR(A)&&MONTH('Table 2'[Program Start Date])<=MONTH(a)))) 
return b

line chart.JPG

Best Regards

Rena

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

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.