Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
ANM_97
Helper IV
Helper IV

Calculate average balance in period

Hello !

 

I have this problem:

I have balances on working days . I need to calculate the average balance over a period of time. How can I do this without multiplying the balance from the last non-working day in the balance?

During the period, the balance of the weekend must also be taken into account, which is supposed to be the one from the last non-working day.

ANM_97_0-1655734995826.png

Expected result:

in period: 2022/04/29 - 2022/04/ 30 -> balance = 200 $
in period 2022/04/29 - 2022/05/02 -> balance = 400$

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @ANM_97 ,

 

I suggest you to try this code to create a measure.

Balance in Period = 
VAR _RELATE_VALUE =
    ADDCOLUMNS (
        'DATE',
        "Related Value",
            VAR _LAST_WORKING_DATE_ID =
                YEAR ( 'DATE'[LAST_WORKING_DATE] ) * 10000
                    + MONTH ( 'DATE'[LAST_WORKING_DATE] ) * 100
                    + DAY ( 'DATE'[LAST_WORKING_DATE] )
            RETURN
                CALCULATE (
                    SUM ( FACT_BALANCES[Value] ),
                    FILTER ( FACT_BALANCES, FACT_BALANCES[DIM_DATE_ID] = _LAST_WORKING_DATE_ID )
                )
    )
RETURN
    SUMX ( _RELATE_VALUE, [Related Value] )

Result is as below.

RicoZhou_0-1655952081739.png

 

Best Regards,
Rico Zhou

 

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

4 REPLIES 4
ANM_97
Helper IV
Helper IV

@v-rzhou-msft  Thank you soooooo much! This measure is WOW!   

v-rzhou-msft
Community Support
Community Support

Hi @ANM_97 ,

 

I suggest you to try this code to create a measure.

Balance in Period = 
VAR _RELATE_VALUE =
    ADDCOLUMNS (
        'DATE',
        "Related Value",
            VAR _LAST_WORKING_DATE_ID =
                YEAR ( 'DATE'[LAST_WORKING_DATE] ) * 10000
                    + MONTH ( 'DATE'[LAST_WORKING_DATE] ) * 100
                    + DAY ( 'DATE'[LAST_WORKING_DATE] )
            RETURN
                CALCULATE (
                    SUM ( FACT_BALANCES[Value] ),
                    FILTER ( FACT_BALANCES, FACT_BALANCES[DIM_DATE_ID] = _LAST_WORKING_DATE_ID )
                )
    )
RETURN
    SUMX ( _RELATE_VALUE, [Related Value] )

Result is as below.

RicoZhou_0-1655952081739.png

 

Best Regards,
Rico Zhou

 

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

@v-rzhou-msft  I have a little problem. For start of year 2022, if i select January,  how can I change the measure so as to extract the balance of the last working day from December 2021? 

I find the solution. I put ALL( FCT_BALANCES) in filter. 

 

FILTER ( ALL(FCT_BALANCES), FCT_BALANCES[DIM_DATE_ID] = ....
 
Thank you !

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.