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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Aggregation Problem regarding finding average for repeated values

Im facing an issue regarding aggregation and Im doing average of a value. I have below values  and Im trying to find the average value but Im not able to get the values correctly. Any help will be greatly appreciated. Here I need to define a measure that will calculate average length of stay ofcourse I need to have this measure at all granular levels. But when i take the sum goes wrong or Im not able to calculate at each level as well. Here the same values repeat for every business date. We need to pick only one Length of Stay for a reservation and then find out the average . Im looking for a solution that will work for individual level as well as when aggregated as well ie in the below scenario at a daily level and also at the hotel level in total.

Average Scenario.JPG

 

 

 

 

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

@Anonymous ,

 

Create measures using dax below:

 

Average Length of Stay for Hotel = 
AVERAGEX (
    SUMMARIZE (
        'Table',
        'Table'[Reservation],
        "Length", CALCULATE (
            MAX ( 'Table'[Length of Stay] ),
            ALLEXCEPT ( 'Table', 'Table'[Reservation] )
        )
    ),
    [Length]
)

Average Length of Stay May be for Busniness Dates 04-Jan to 05-Jan = 
AVERAGEX (
    SUMMARIZE (
        FILTER (
            'Table',
            'Table'[Business Date]
                IN { DATEVALUE ( "04-jan-20" ), DATEVALUE ( "05-jan-20" ) }
        ),
        'Table'[Reservation],
        "Length", CALCULATE (
            MAX ( 'Table'[Length of Stay] ),
            ALLEXCEPT ( 'Table', 'Table'[Reservation] )
        )
    ),
    [Length]
)

 

Capture.PNG 

 

Community Support Team _ Jimmy Tao

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

5 REPLIES 5
v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

Create measures using dax below:

 

Average Length of Stay for Hotel = 
AVERAGEX (
    SUMMARIZE (
        'Table',
        'Table'[Reservation],
        "Length", CALCULATE (
            MAX ( 'Table'[Length of Stay] ),
            ALLEXCEPT ( 'Table', 'Table'[Reservation] )
        )
    ),
    [Length]
)

Average Length of Stay May be for Busniness Dates 04-Jan to 05-Jan = 
AVERAGEX (
    SUMMARIZE (
        FILTER (
            'Table',
            'Table'[Business Date]
                IN { DATEVALUE ( "04-jan-20" ), DATEVALUE ( "05-jan-20" ) }
        ),
        'Table'[Reservation],
        "Length", CALCULATE (
            MAX ( 'Table'[Length of Stay] ),
            ALLEXCEPT ( 'Table', 'Table'[Reservation] )
        )
    ),
    [Length]
)

 

Capture.PNG 

 

Community Support Team _ Jimmy Tao

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

Anonymous
Not applicable

@v-yuta-msft 

Thanks a lot for your reply. Can we have a single measure or rather a generic measure that will work across all or both the scenarios that it will work for any granularity .
Here in the below example we are seeing a filter hardcoded as 04 and 5th Jan as well.

You have to try something like this. But before that, you have to make sure you unique reservation

CALCULATE(countx(SUMMARIZE(filter(CROSSJOIN(Table2,Dim_Date),Dim_Date[Calendar_Date] >= Table2[StayStartDate] && Dim_Date[Calendar_Date]<= Table2[StayEndDate]),Dim_Date[Calendar_Date]),Dim_Date[Calendar_Date]),CROSSFILTER(Dim_Date[Calendar_Date],Table2[StartDate],None))

 

In summarize , you can add reservation id as one group by along with date

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@v-yuta-msft @amitchandak  thanks much for the reply. 

 

The calculated measure  in the below format seem to work in almost all scenarios.. Testing with more scenarios. Thanks for the help. The below dax works.

 

AVERAGEX(SUMMARIZE(RESERVATION_DAILY;RESERVATION_DAILY[RESV_ID];"LENGTH";CALCULATE (
MAX (RESERVATION_DAILY[LENGTH_OF_STAY]);
ALLEXCEPT(RESERVATION_DAILY;RESERVATION_DAILY[RESV_ID])));[LENGTH])
Anonymous
Not applicable

@v-yuta-msft 

 

Thanks very much for the solution regarding the above average calculation. However Im getting error when this is done for larger number of rows say for 1 year when i try to fetch the average for a Hotel . Im getting the error saying limitation of 1 million rows in Direct Query. I totally understand the scenario. But when i check in the database for the particular hotel for that year I dont have 1 million records, I only have 205237 records. Please advice.

 

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.