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

3 month rolling average data table

Hi,

 

I posted a question on this forum a while back regarding getting 3 month rolling average data (answered by @Jihwan_Kim😞 Solved: 3 month rolling data visual - Microsoft Power BI Community

 

The attached .pbix was provided with the following DAX measure: 

ArslanManzoor_0-1623749310239.png

 

However this doesn't seem to be giving me the correct average values in the table visual:

 

ArslanManzoor_1-1623749345485.png

.pbix file:

https://www.dropbox.com/s/gwid24yyo4isxtx/arslanmanzoor.pbix?dl=0

 

For example, for May 2021, task A, the raw data values are 42, 42, 42, so should give an average value of 42. However in the visual I am getting an average of 40.63.

 

Is there a mistake in the DAX formula?

 

Thanks in advance!

 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @ArslanManzoor ,

 

The measure you are calculating is the average value of the previous 3 months in this case you are getting for may the values between February and April and making the average so the data is:

MFelix_0-1623853377773.png

If you make the average you get the 40.63.

 

To what I read you want to have the values of the montlhy average on the last 3 month so you want that if the value is on the last 3 month show the average otherwise do not show.

 

Redo your measure to:

TimeTakenAverageValue = 
VAR MaxFactDate =
    CALCULATE ( MAX ( 'Calendar'[Date] ), ALL ( 'Calendar' ) )
VAR Edate =
    EDATE ( MaxFactDate, -2 )
RETURN
    SWITCH (
        TRUE (),
        SELECTEDVALUE ( AxisTable[Month & Year] ) = "Current",
            CALCULATE (
                [Time Taken Avg],
                FILTER (
                    ALL ( 'Calendar' ),
                    'Calendar'[Month & Year] <> MAX ( 'Calendar'[Month & Year] )
                )
            ),
        MAX ( 'Calendar'[Date] ) <= MaxFactDate
            && MAX ( 'Calendar'[Date] ) >= Edate, CALCULATE ( AVERAGE ( Data[Time taken] ) )
    )

 

check result below and in attach PBIX file.

MFelix_1-1623856244167.png

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

1 REPLY 1
MFelix
Super User
Super User

Hi @ArslanManzoor ,

 

The measure you are calculating is the average value of the previous 3 months in this case you are getting for may the values between February and April and making the average so the data is:

MFelix_0-1623853377773.png

If you make the average you get the 40.63.

 

To what I read you want to have the values of the montlhy average on the last 3 month so you want that if the value is on the last 3 month show the average otherwise do not show.

 

Redo your measure to:

TimeTakenAverageValue = 
VAR MaxFactDate =
    CALCULATE ( MAX ( 'Calendar'[Date] ), ALL ( 'Calendar' ) )
VAR Edate =
    EDATE ( MaxFactDate, -2 )
RETURN
    SWITCH (
        TRUE (),
        SELECTEDVALUE ( AxisTable[Month & Year] ) = "Current",
            CALCULATE (
                [Time Taken Avg],
                FILTER (
                    ALL ( 'Calendar' ),
                    'Calendar'[Month & Year] <> MAX ( 'Calendar'[Month & Year] )
                )
            ),
        MAX ( 'Calendar'[Date] ) <= MaxFactDate
            && MAX ( 'Calendar'[Date] ) >= Edate, CALCULATE ( AVERAGE ( Data[Time taken] ) )
    )

 

check result below and in attach PBIX file.

MFelix_1-1623856244167.png

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



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.