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

Compare current period to the average of that period of the last X years.

Hi, I'm trying to compare a current period with the average of the same period of the last X years.

 

I have data from 2009 of several weather stations. The important columns are:

DATE (which is month,day and year), RAIN, WIND SPEED, TEMPERATURE

DATETEMPWIND SPEEDRAIN
01/01/200912.260.840
01/02/200912.80.790
01/03/200911.540.491
01/04/200910.470.931.6
01/05/20099.070.810.03
01/06/20099.451.110
01/07/200961.480
01/08/20094.91.434.2
01/09/20096.491.110.6
01/10/20094.741.626.4
01/11/20099.741.35.8
01/12/20098.931.180
1/13/20099.111.90
1/14/20099.762.020
1/15/20098.251.510
1/16/20099.461.250

 

 

I've set a date report filter, like this one:

ciervax_0-1618557975827.png

What I am trying to get, is a table per month, from 01/07/2020 till 16/04/2021. With the current values on each column of:

RAIN, WIND SPEED, TEMPERATURE, and the same number of columns with a comparing the current period with the average from 2009 on the same period.

For example, the RAIN Comparision column should be, compare the current period to the TOTAL average of:

01/07/2019 - 16/04/2020

01/07/2018 - 16/04/2019

01/07/2017 - 16/04/2018

01/07/2016 - 16/04/2017....

 

So I can get the % above or lower of the current period against the average of the total data I have, on the same period.

 

About temperature, I want to compare against the average of days below 3ºC and another column below 0ºC.

 

Wind speed I want to do similar to temperature, but, wind speed above: 11.1 and days above 15.2

 

I can share the full .csv , can I link it here directly? or is it forbidden?

 

Thank you in advance.

9 REPLIES 9
lbendlin
Super User
Super User

"Just to clarify, I need a column with the current period, and on the right side another column with the comparison of that period to the average of all years I have, except the current."

 

Now you are saying you need averages per month?  Please restate your request with more detail and with full context.

v-yingjl
Community Support
Community Support

Hi @ciervax ,

Based on the sample data, the RAIN Comparsion measure could be like this:

RAIN Comparison = 
AVERAGEX (
    FILTER (
        ALL ( 'WEATHER' ),
        MONTH ( 'WEATHER'[DATE] ) >= 4
            && MONTH ( 'WEATHER'[DATE] ) <= 7
            && DAY ( 'WEATHER'[DATE] ) >= 1
            && DAY ( 'WEATHER'[DATE] ) <= 16
            && YEAR ( 'WEATHER'[DATE] )
                <= CALCULATE (
                    YEAR ( MIN ( 'Calendar'[Date] ) ),
                    ALLSELECTED ( 'Calendar'[Date] )
                )
    ),
    [RAIN]
)

By the way, the filter condition as your mentioned about temp and wind speed when I applied in the sample table, it looks like have no data match it so I created the simliar measure to calculate the average temporarily.

TEMP Comparsion = 
AVERAGEX (
    FILTER (
        ALL ( 'WEATHER' ),
        MONTH ( 'WEATHER'[DATE] ) >= 4
            && MONTH ( 'WEATHER'[DATE] ) <= 7
            && DAY ( 'WEATHER'[DATE] ) >= 1
            && DAY ( 'WEATHER'[DATE] ) <= 16
            && YEAR ( 'WEATHER'[DATE] )
                <= CALCULATE (
                    YEAR ( MIN ( 'Calendar'[Date] ) ),
                    ALLSELECTED ( 'Calendar'[Date] )
                )
    ),
    [TEMP]
)
Wind Comparsion = 
AVERAGEX (
    FILTER (
        ALL ( 'WEATHER' ),
        MONTH ( 'WEATHER'[DATE] ) >= 4
            && MONTH ( 'WEATHER'[DATE] ) <= 7
            && DAY ( 'WEATHER'[DATE] ) >= 1
            && DAY ( 'WEATHER'[DATE] ) <= 16
            && YEAR ( 'WEATHER'[DATE] )
                <= CALCULATE (
                    YEAR ( MIN ( 'Calendar'[Date] ) ),
                    ALLSELECTED ( 'Calendar'[Date] )
                )
    ),
    [WIND SPEED]
)

re.png

 

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

Thank you for your help.

The problem I see here is that for all months or days, the % is the same.

Example of your measure:

ciervax_0-1618907873037.png

 

As you can see, for all ID1 and ID2 the value is the same 0.85, and in all months the values are the same 0.85.

Should be different per month and ID, and then the total average of that period on the bottom of the table.

 

thanks in advace.

Hi @ciervax ,

Use Allexcept() to replace All() function in the measure like:

ALLEXCEPT ( 'WEATHER', [your ID column], [your month column] )

Use Hasonefilter() or Hasonevalue() to modify the total value, please refer: Dealing with Measure Totals 

 

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

Thanks, Ying,


I've tried yesterday and today to solve the issue, this is what I have right now, focusing on RAIN column:

 

 

RAIN Comparison = 
AVERAGEX (
    FILTER (
        ALLEXCEPT ( 'WEATHER',WEATHER[ID1],WEATHER[Month] ),
        MONTH ( 'WEATHER'[DATE] ) >= 4
            && MONTH ( 'WEATHER'[DATE] ) <= 7
            && DAY ( 'WEATHER'[DATE] ) >= 1
            && DAY ( 'WEATHER'[DATE] ) <= 16
            && YEAR ( 'WEATHER'[DATE] )
                <= CALCULATE (
                    YEAR ( MIN ( 'Calendar'[Date] ) ),
                    ALLSELECTED ( 'Calendar'[Date] )
                )
    ),
    [RAIN]
)

 

 

Result:

ciervax_0-1619114687868.png


I've tried the following:

 

RAIN Comparison = 
AVERAGEX (
    FILTER (
        ALLEXCEPT ( 'WEATHER',WEATHER[ID1],WEATHER[Month] ),
        MONTH ( 'WEATHER'[DATE] ) >= 4
            && MONTH ( 'WEATHER'[DATE] ) <= 7
            && DAY ( 'WEATHER'[DATE] ) >= 1
            && DAY ( 'WEATHER'[DATE] ) <= 16
            && YEAR ( 'WEATHER'[DATE] )
                <= CALCULATE (
                    YEAR ( MIN ( 'WEATHER'[DATE]) ),
                    ALLSELECTED ( 'WEATHER'[DATE] )
                )
    ),
    [RAIN]
)

 

 

ciervax_1-1619115074055.png


But still no luck, I am not able to get in column rain, the rain of the current period, and RAIN comparison difference between the current period vs average of the last X years.

 


This is my target but with the correct numbers on the column "RAIN vsXy"

ciervax_2-1619115237803.png

 

Thanks in advance, really appreciate your help.

lbendlin
Super User
Super User

please go ahead and share the .csv

 

In your example the period stretches over two years. How do you then define "the same period in 2009" ?

Because my data starts 01/01/2009, the first period should be: 01/07/2009 - 16/04/2010.

Just to clarify, I need a column with the current period, and on the right side another column with the comparison of that period to the average of all years I have, except the current.

the csv: 

 

 

https://easyupload.io/lgdukm

 

 

Hi @ciervax ,

Seems that the sample file has been deleted. You can consider to re-sharing it for further discussion.

 

Best Regards,
Community Support Team _ Yingjie Li

Hi,

 

Here it is: https://easyupload.io/lgdukm

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