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

Line and Stacked Colum - How to Show Average on Line?

I want to show a student's login activity per day (Event_Type = "Login") as columns and I want to show the course average for the course that the student is on as the line on the same graph.

 

Here is the data: https://www.dropbox.com/scl/fi/70aa2cgr1chegmrdlitdg/exampledata.xlsx?rlkey=2m5ox5ix7v65v5dsf3usl4e8...

 

 

What measure do I need for the line?

 

My measure for the columns is as follows: 

Count of Logins =
CALCULATE (
    SUM ( CourseData[Total] ),
    CourseData[Event_Type] = "Login"
)

 

My data is structured as follows and note that this table contains several students and several courses:

cw900_0-1713782164366.png

 

How do I create a measure that says take the course of the student selected and calculate the average logins for that course and plot on the same visual?

 

The expected result is that when you selected Nina who is studing Geology, the line and column chart will show Nina's logins every month as columns and plot the average logins for Geology on the line.

 

cw900_0-1713796219311.png

cw900_1-1713796230113.png

 

 

1 ACCEPTED SOLUTION

In the Allexcepted put the column date that your are using in the charte.

Allexcepted will remove all filter on that table except on the column you mention, so I think it Could solve your problem.

Try...





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




View solution in original post

15 REPLIES 15
_AAndrade
Super User
Super User

Hi @cw900,

Please try this Dax measure:

AverageCourse = 
AVERAGEX(
        ALL(T_Logins[Student]),
        CALCULATE(
            AVERAGE(T_Logins[Total])
        )
)


T_Logins is my table, so you need to change this to your table name. I did some test from my side and it's working fine.





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Hi

 

I don't think I was clear in my question. There are different courses in this table. Using that measure the average line is the same for every student because it is not taking into account the course that they are on.

Please provide one example with some data and the expected output.

I think that way would be easy to underdtand 





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Here's the data:

https://www.dropbox.com/scl/fi/70aa2cgr1chegmrdlitdg/exampledata.xlsx?rlkey=2m5ox5ix7v65v5dsf3usl4e8...

 

Expected result is that when you selected Nina who is studing Geology, the line and column chart will show Nina's logins every month as columns and plot the average logins for Geology on the line.

 

cw900_0-1713791703161.pngcw900_1-1713791708494.png

 

Please take a look it this is what you're looking for:

_AAndrade_0-1713799824081.png


My AverageCourse measure it this:

AverageCourse = 
IF(
    NOT(ISBLANK([Count of Logins])),
    CALCULATE(
        [SimpleAvg],
        FILTER(
            ALL(T_Logins),
            T_Logins[Event_Type]="Login" && T_Logins[Student_Course_Name] IN VALUES(T_Logins[Student_Course_Name])
        )

    )
)




Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




What is 

[SimpleAvg]

?

 

Also, that doesn't look right because the average value doesn't change each day. I need average value for the course on each day, so it will change every day. 

@cw900,

See if this solve your problem:

_AAndrade_0-1713804637069.png


Measures:

SimpleAvg = 
AVERAGE (T_Logins[Total])

New Avg = 
IF(
    NOT(ISBLANK([Count of Logins])),
    CALCULATE(
            [SimpleAvg],
            REMOVEFILTERS(T_Logins[Student]),
            T_Logins[Event_Type]="Login"
    )
)




Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Ok that is much closer. I changed the measure to this:

New Avg v2 =
    CALCULATE(
            AVERAGE (CourseData[Total]),
            CourseData[Event_Type]="Login",
            REMOVEFILTERS(CourseData[Student])
    )
 
This works in the example here but when I apply this to my real data it doesn't work. I think because my real table contains many other fields other than Student_Course_Name.
 
Is there any way in that measure to say only calculate the average based on Student_Course_Name?

Try something using Allexcepted.

DAX is all about context and for that reason is important to have the right example.

In my example is working fine on my side...





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Hmmm. ALLEXCEPT looks useful but I'm struggling to work out the implementation.

 

The following measure just gives me the same average on each date.

 

New Avg v3 =
    CALCULATE(
            AVERAGE (CourseData[Total]),
            CourseData[Event_Type]="Login",
            ALLEXCEPT(CourseData, CourseData[Student_Course_Name])
    )
 

cw900_0-1713858253539.png

 

In the Allexcepted put the column date that your are using in the charte.

Allexcepted will remove all filter on that table except on the column you mention, so I think it Could solve your problem.

Try...





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




That was it 🙂

Thank you.

Great. You're welcome.





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Uzi2019
Super User
Super User

Hi @cw900 

A simple avg formula is total sum / no of count.
Create same formula through measure.

Add your formula here in this property of bar chart

Uzi2019_0-1713784490789.png

 

 

I hope I answered your question!

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

How do I identify the course that the student is on? And how to I tell my measure for the average to ignore the student that I've selected and get me the average for the course they are on?

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Power BI Monthly Update - May 2024

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