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
chili
Frequent Visitor

Adding Weekday average line into stacked column chart

Hi, I am trying to add a weekday average line into a stacked column chart, but I cannot find a solution so far

chili_0-1650359438109.png

 

 

Here is my table

DateTeamvalueWeekday
4/8/2022a10Fri
4/8/2022b20Fri
4/8/2022c30

Fri

....
4/15/2022a10Fri
4/15/2022b12Fri
4/15/2022c30Fri
4/16/2022a10Sat
4/16/2022b73Sat
4/16/2022c16Sat
4/17/2022a22Sun
4/17/2022b45Sun
4/17/2022c50Sun

 

I want to calculate the average by the weekday over the last weeks, for example, on 15 April (Fri), I get the average of the last two Fridays, 1st April and 8th April. on 16 April (Sat), I get the average of the last two Saturdays, 2nd April and 9th April. Then I can add this as a line in the chart, to compare the performance of the current weekday.

 

It would be great to get any suggestions or help from you!

2 ACCEPTED SOLUTIONS
v-henryk-mstf
Community Support
Community Support

Hi @chili ,

 

According to your description, does the following test result meet your requirements.

M =
VAR cur_ =
    SELECTEDVALUE ( 'Table'[value] )
VAR day1 =
    CALCULATE ( MAX ( 'Table'[value] ), 'Table'[Date] - 7 = cur_ )
VAR day2 =
    CALCULATE ( MAX ( 'Table'[value] ), 'Table'[Date] - 14 = cur_ )
VAR day3 =
    CALCULATE ( MAX ( 'Table'[value] ), 'Table'[Date] = cur_ )
RETURN
    ( day1 + day2 + day3 ) / 3

vhenrykmstf_0-1650617777099.png

 


If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


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

Hello, sorry for the late reply, I was testing out different solutions, but unfortunately the measure above cannot return the correct average number each weekday. I made few changes which inspired by your solution, and I finally got the right numbers for that:

 

First I created two measures:

1_week before sum =
VAR __max = MAX('Table'[date])
RETURN
calculate(SUMX('Table', 'Table'[value]),'Table'[date]=__max-7)

 

 

and

 

 

2_week before sum =
VAR __max = MAX('Table'[date])
RETURN
calculate(SUMX('Table', 'Table'[value]),'Table'[date]=__max-14)


then I simply get the average by creating the third measure

 

2 weeks average = ([1_week before sum] + [2_week before sum]/ 2 

 

Finally, I used 2 weeks' average to be the value in the constant line, like what you did before. That's how I got the weekday average. Thanks again for your help!

View solution in original post

5 REPLIES 5
v-henryk-mstf
Community Support
Community Support

Hi @chili ,

 

According to your description, does the following test result meet your requirements.

M =
VAR cur_ =
    SELECTEDVALUE ( 'Table'[value] )
VAR day1 =
    CALCULATE ( MAX ( 'Table'[value] ), 'Table'[Date] - 7 = cur_ )
VAR day2 =
    CALCULATE ( MAX ( 'Table'[value] ), 'Table'[Date] - 14 = cur_ )
VAR day3 =
    CALCULATE ( MAX ( 'Table'[value] ), 'Table'[Date] = cur_ )
RETURN
    ( day1 + day2 + day3 ) / 3

vhenrykmstf_0-1650617777099.png

 


If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


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

Hello, sorry for the late reply, I was testing out different solutions, but unfortunately the measure above cannot return the correct average number each weekday. I made few changes which inspired by your solution, and I finally got the right numbers for that:

 

First I created two measures:

1_week before sum =
VAR __max = MAX('Table'[date])
RETURN
calculate(SUMX('Table', 'Table'[value]),'Table'[date]=__max-7)

 

 

and

 

 

2_week before sum =
VAR __max = MAX('Table'[date])
RETURN
calculate(SUMX('Table', 'Table'[value]),'Table'[date]=__max-14)


then I simply get the average by creating the third measure

 

2 weeks average = ([1_week before sum] + [2_week before sum]/ 2 

 

Finally, I used 2 weeks' average to be the value in the constant line, like what you did before. That's how I got the weekday average. Thanks again for your help!

Adescrit
Impactful Individual
Impactful Individual

Hi @chili ,

 

You could try a measure like this:

 

Average Last two weeks =
CALCULATE (
    AVERAGE ( 'Table'[value] ),
    FILTER (
        'Calendar',
        'Calendar'[Weekday] = SELECTEDVALUE ( 'Calendar'[Weekday] )
            && 'Calendar'[Date]
                >= SELECTEDVALUE ( 'Calendar'[Date] ) - 14
    )
)

 

Hopwever, whether it works or not I think depends on whether you are filtering one or all teams. Let me know.


Did I answer your question? Mark my post as a solution!
My LinkedIn

Hi @Adescrit 

 

thanks for your reply. I tried to make this measure, but it doesn't return anything (no line in the chart or empty column in a table). Here is my data schema:

chili_0-1650530191060.png

I highly appreciate your help!

chili
Frequent Visitor

Hi, is there anyone who could help? I tried the solution in this post

But it doesn't work for my report

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.