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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
ihmerr2c
Frequent Visitor

Simplifying so that it works faster

AllocatedAmountp2 =
CALCULATE (
    SUMX (
        SUMMARIZE (
            'mediware vw_EMRToBilling',
            'mediware dimFacility'[FacilityName],  -- Use the correct column name
            'mediware vw_EMRToBilling'[bsr_Visits],
            'mediware vw_EMRToBilling'[feeschedc],
            'mediware vw_EMRToBilling'[Contractper],
            "TotalAmount", [TotalAmountMeasure],
            "ServedHours", [ServedHoursMeasure],
            "TotalServedHoursWeek", [TotalServedHoursWeekMeasure]
        ),
        IF (
            [bsr_Visits] > 1,
            [TotalAmount] * DIVIDE([ServedHours], [TotalServedHoursWeek]) * [Contractper],
            IF (
                [feeschedc] = "Unknown",
                [TotalAmount] * 1,
                [TotalAmount] * [Contractper]
            )
        )
    )
)
I have this measure that works correct in the visuals, but it works really slow all of my visuals can any one recom. a way to rewrite it so that it works faster or suggest another way to get the same results?

Heres my data model

ihmerr2c_0-1703963992625.png

 

2 REPLIES 2
Fowmy
Super User
Super User

@ihmerr2c 

Try the following version:

AllocatedAmountp2 =

    SUMX (
        ADDCOLUMNS (
            SUMMARIZE (
                'mediware vw_EMRToBilling',
                'mediware dimFacility'[FacilityName],
                'mediware vw_EMRToBilling'[bsr_Visits],
                'mediware vw_EMRToBilling'[feeschedc],
                'mediware vw_EMRToBilling'[Contractper]
            ),
            "TotalAmount", [TotalAmountMeasure],
            "ServedHours", [ServedHoursMeasure],
            "TotalServedHoursWeek", [TotalServedHoursWeekMeasure]
        ),
        VAR __TotalAmount = [TotalAmount]
        VAR __Contractper = [Contractper]
        RETURN
            IF (
                [bsr_Visits] > 1,
                __TotalAmount * DIVIDE ( [ServedHours], [TotalServedHoursWeek] ) * __Contractper,
                IF ( [feeschedc] = "Unknown", __TotalAmount * 1, __TotalAmount * __Contractper )
            )
    )



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

123abc
Community Champion
Community Champion

  1. Avoid Using SUMMARIZE in CALCULATE: The SUMMARIZE function can be computationally expensive, especially if your data table is large. Instead, try to create separate measures for aggregated calculations and use them in your main measure.

  2. Break Down the Measure: Try to break down the measure into smaller parts and then combine them. For instance, create separate measures for TotalAmount, ServedHours, and TotalServedHoursWeek and then use them in your main measure.

  3. Optimize IF Conditions: Instead of using nested IF conditions, try to use logical functions like SWITCH.

Here's a simplified version of your measure:

 

AllocatedAmountp2 =
VAR TotalAmountValue = [TotalAmountMeasure]
VAR ServedHoursValue = [ServedHoursMeasure]
VAR TotalServedHoursWeekValue = [TotalServedHoursWeekMeasure]

RETURN
CALCULATE (
SUMX (
'mediware vw_EMRToBilling',
VAR CalculatedAmount =
SWITCH (
TRUE (),
'mediware vw_EMRToBilling'[bsr_Visits] > 1, TotalAmountValue * DIVIDE(ServedHoursValue, TotalServedHoursWeekValue) * 'mediware vw_EMRToBilling'[Contractper],
'mediware vw_EMRToBilling'[feeschedc] = "Unknown", TotalAmountValue * 1,
TotalAmountValue * 'mediware vw_EMRToBilling'[Contractper]
)
RETURN
CalculatedAmount
)
)

 

Please note the following:

  • This is a simplified version, and you may need to adjust it based on your specific requirements and data model.
  • Ensure that the individual measures (TotalAmountMeasure, ServedHoursMeasure, TotalServedHoursWeekMeasure) are optimized for performance.
  • Consider creating necessary relationships, indexes, or optimizing your data model to improve overall performance.

If the performance issue persists, you might need to look into optimizing your data model, considering hardware resources, or restructuring your data.

 

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

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

Helpful resources

Announcements
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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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