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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
MPetramalo214
Helper I
Helper I

Iterative Expression Optimization

Hi everyone.  I'm trying to create a dax query that will accomplish a couple things; but I'm getting timeout errors, so I know that I need to make it more efficient - I just can't find a good way to do that.

 

Goal: Create a DAX Measure that will calculate the number of surveys that would be expected to go out based on hotel checkouts.

 - I'm currently doing this by creating a summarized table to check for every customer id (~250K entries).  The first column will check if the customer had a reservation check-out on the date we're looking at.  The second column checks if the owner had a reservation check-out in the 30 days prior to date.  We then check if the first column returns true, and the second returns false.  These customers would be expected to have recieved a survey.

 

 

EVALUATE
SUMX(
    SUMMARIZE(
        CROSSJOIN(Customers, 'Calendar'),
        Customers[Owner Id],
        "_survey", IF(
            CALCULATE(
                COUNTROWS(Reservations),
                FILTER(
                    ALLEXCEPT(Reservations, Locations[location_name]),
                    Reservations[Owner Id] = SELECTEDVALUE(Customers[Owner Id])
                    && DATEVALUE(Reservations[Check-Out Date]) = MAX('Calendar'[Date])
                )
            ) > 0, 1, 0
        ),
        "_last30", IF(
            CALCULATE(
                COUNTROWS(Reservations),
                FILTER(
                    ALLEXCEPT(Reservations, Locations[location_name]),
                    Reservations[Owner Id] = SELECTEDVALUE(Customers[Owner Id])
                    && DATEVALUE(Reservations[Check-Out Date]) >= (MAX('Calendar'[Date])-30)
                    && DATEVALUE(Reservations[Check-Out Date]) < MAX('Calendar'[Date])
                )
            ) > 0, 0, 1
        )
    ),
    IF([_survey] = 1 && [_last30] = 1, 1, 0)
)

 

MPetramalo214_0-1658323825885.png

The table above is the result of just the SUMMARIZE expression.  The SUMX function will add one anytime the values are both 1. 

The table below is the SUMX result in Power BI - it prints out the correct value per day; but I have been unsuccessful in summing this table to get a rolling total.

MPetramalo214_2-1658324597624.png

 

Using the values in the table above, my expected result would be

DateNPS Surveys Goal (Rolling)
2022-01-0119
2022-01-0268
2022-01-03112
2022-01-04136
2022-01-05149
2022-01-06170
2022-01-07178
2022-01-08190
2022-01-09216

 

I've tried doing the standard quick measure for running total over time, but that didn't produce correct results.  I also tried a few other methods such as SUMX over the SUMX using the calendar table but the query times-out in DAX Studio; so I'm concerned its an efficiency issue. 

 

I imagine there is a better way to iterate only a subset of customers, but I'm not sure how I'd get that value.  But that would cut iteration from 250K customers, to a much smaller value.  Preferably to customers who actually checked out that day, but I'm not sure where I'd get that.

3 REPLIES 3
v-easonf-msft
Community Support
Community Support

Hi, @MPetramalo214 

Have you tried the following formula?

Measure1 =
SUMX ( VALUES ( 'Calendar'[DATE] ), [NPS Surveys Goal] )

Best Regards,
Community Support Team _ Eason

Hi @v-easonf-msft - I did try this formula; but it produced incorrect results.  There were days where the value would go down from day prior; but there should never be an instance where the value was less than day prior.  (You don't ever lose customers who would be eligible for a survey, you just add the new users who are)

lbendlin
Super User
Super User

Simplify the query until it doesn't time out in DAX Studio. Then look at the query plan it produces. Look for excessive number of records.

 

Try filtering first for the items with the biggest impact (low cardinality) and then add the other filters in order of increased cardinality/reduced impact.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.