cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Anonymous
Not applicable

How to get average reference two last specific day in a calculated table?

Hi guys, i need a help!

I'd like to receive the average from the two last Mondays in my month and fill the current Monday. It will be a kind of forecast in my business case. At the moment, i have the average of days, but i dont know how to get the average in a calculated column. Follow example below. Any help is appreciated. 

 

example.png

1 ACCEPTED SOLUTION

Accepted Solutions
Moderator v-qiuyu-msft
Moderator

Re: How to get average reference two last specific day in a calculated table?

Hi @Anonymous, 

 

You can create a measure below: 

 

Measure =
VAR CurrentDate =
    MAX ( 'Table1'[Data Venda] )
VAR MinDate =
    CALCULATE (
        MIN ( 'Table1'[Data Venda] ),
        FILTER (
            ALLSELECTED ( Table1 ),
            MONTH ( 'Table1'[Data Venda] ) = MONTH ( CurrentDate )
        )
    )
RETURN
    IF (
        CurrentDate = MinDate,
        CALCULATE (
            AVERAGE ( Table1[Total Vendas] ),
            FILTER (
                ALLSELECTED ( 'Table1' ),
                WEEKNUM ( 'Table1'[Data Venda] )
                    >= WEEKNUM ( CurrentDate ) - 2
                    && WEEKNUM ( 'Table1'[Data Venda] ) < WEEKNUM ( ( CurrentDate ) )
            )
        ),
        BLANK ()
    )

q1.PNG

 

Best Regards,
Qiuyun Yu 

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

2 REPLIES 2
Moderator v-qiuyu-msft
Moderator

Re: How to get average reference two last specific day in a calculated table?

Hi @Anonymous, 

 

You can create a measure below: 

 

Measure =
VAR CurrentDate =
    MAX ( 'Table1'[Data Venda] )
VAR MinDate =
    CALCULATE (
        MIN ( 'Table1'[Data Venda] ),
        FILTER (
            ALLSELECTED ( Table1 ),
            MONTH ( 'Table1'[Data Venda] ) = MONTH ( CurrentDate )
        )
    )
RETURN
    IF (
        CurrentDate = MinDate,
        CALCULATE (
            AVERAGE ( Table1[Total Vendas] ),
            FILTER (
                ALLSELECTED ( 'Table1' ),
                WEEKNUM ( 'Table1'[Data Venda] )
                    >= WEEKNUM ( CurrentDate ) - 2
                    && WEEKNUM ( 'Table1'[Data Venda] ) < WEEKNUM ( ( CurrentDate ) )
            )
        ),
        BLANK ()
    )

q1.PNG

 

Best Regards,
Qiuyun Yu 

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

Anonymous
Not applicable

Re: How to get average reference two last specific day in a calculated table?

Hello @v-qiuyu-msft it resolved my problem! Thanks a lot!

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

January 2020 Community Highlights

January 2020 Community Highlights

Make sure you didn't miss any of the things that happened in the community in January!

Top Solution Authors
Top Kudoed Authors