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
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
v-qiuyu-msft
Community Support
Community Support

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
v-qiuyu-msft
Community Support
Community Support

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.
Anonymous
Not applicable

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

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.