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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
a4
Helper III
Helper III

How to reduce the Dax query

Hi ,

I have written down a dax query to calculate the annualised premium for leap year and non leap year.

 

The query is bit complex that's why it is throwing "resource limit exceeds error "in Power Bi Service.

 

optimize.PNG

 

Please find below the query:

 

Annualised Gross Perm = IF([Distinct Count]>1,
SUMX(


TOPN(1,


GROUPBY(
'Club Year Data','Club Year Data'[Related risk ref],'Club Year Data'[Related quoteref],'Club Year Data'[spl_stagingid],
'Club Year Data'[perdaygrossperm],'Club Year Data'[Trim name],'Club Year Data'[Broker Group Name],'Club Year Data'[Product Name],'Club Year Data'[startdate],'Year-Days'[Days in Year],'Club Year Data'[enddate],'Year-Days'[Year]),


'Club Year Data'[spl_startdate],DESC),

 

IF('Club Year Data'[startdate]<DATE(LOOKUPVALUE('Year-Days'[Year],'Year-Days'[Days in Year],366),2,29) &&
DATE(LOOKUPVALUE('Year-Days'[Year],'Year-Days'[Days in Year],366),2,29)<'Club Year Data'[enddate],
'Club Year Data'[perdaygrossperm]*366,'Club Year Data'[perdaygrossperm]*365)),

 

SUMX(


GROUPBY(
'Club Year Data','Club Year Data'[Related quoteref],'Club Year Data'[Related risk ref],'Club Year Data'[spl_stagingid],
'Club Year Data'[spl_perdaygrossperm],'Club Year Data'[Trim name],'Club Year Data'[Broker Group Name],'Club Year Data'[Product Name],'Year-Days'[Days in Year],'Club Year Data'[startdate],'Club Year Data'[enddate],'Year-Days'[Year]),


IF('Club Year Data'[startdate]<DATE(LOOKUPVALUE('Year-Days'[Year],'Year-Days'[Days in Year],366),2,29) &&

DATE(LOOKUPVALUE('Year-Days'[Year],'Year-Days'[Days in Year],366),2,29)<'Club Year Data'[enddate],
'Club Year Data'[perdaygrossperm]*366,'Club Year Data'[perdaygrossperm]*365))


)

 

Formula for distinct count=DISTINCTCOUNT(Club Year Data[Related Quote ref])

 

After writing this formula(Annualised Gross Perm) I have again grouped it :

 

Annual Gross Premium =
SUMX(GROUPBY('Club Year Data','Club Year Data'[Club Year],'Club Year Data'[Related risk ref],'Club Year Data'[Trim name],'Club Year Data'[Broker Group Name],'Club Year Data'[Product Name]),
[Annualised Gross Perm])
 
Please suggest any alternative formula to this.
 
Kind Regards
Amit Kumar

 

3 REPLIES 3
v-deddai1-msft
Community Support
Community Support

Hi @a4 ,

 

The error occurs when the measure attempts to query too much data for the server to complete the result with the available resources.

 

You need to delete remove unnecessary columns and use parameters in your measure:

Annualised Gross Perm =

VAR A =

    GROUPBY (

        'Club Year Data',

        'Club Year Data'[perdaygrossperm],

        'Club Year Data'[Broker Group Name],

        'Club Year Data'[Product Name],

        'Club Year Data'[startdate],

        'Year-Days'[Days in Year],

        'Club Year Data'[enddate],

        'Year-Days'[Year]

    )

RETURN

    IF (

        [Distinct Count] > 1,

        SUMX (

            TOPN ( 1, A, 'Club Year Data'[spl_startdate], DESC ),

            IF (

                'Club Year Data'[startdate]

                    < DATE ( LOOKUPVALUE ( 'Year-Days'[Year], 'Year-Days'[Days in Year], 366 ), 2, 29 )

                    && DATE ( LOOKUPVALUE ( 'Year-Days'[Year], 'Year-Days'[Days in Year], 366 ), 2, 29 ) < 'Club Year Data'[enddate],

                'Club Year Data'[perdaygrossperm] * 366,

                'Club Year Data'[perdaygrossperm] * 365

            )

        ),

        SUMX (

            A,

            IF (

                'Club Year Data'[startdate]

                    < DATE ( LOOKUPVALUE ( 'Year-Days'[Year], 'Year-Days'[Days in Year], 366 ), 2, 29 )

                    && DATE ( LOOKUPVALUE ( 'Year-Days'[Year], 'Year-Days'[Days in Year], 366 ), 2, 29 ) < 'Club Year Data'[enddate],

                'Club Year Data'[perdaygrossperm] * 366,

                'Club Year Data'[perdaygrossperm] * 365

            )

        )

    )

If that doesn't help, would you please inform us more detailed information( your  data(by OneDrive for Business)) if possible? Then we will help you more correctly. You may purchase Power BI Premium capacity for your organization, see What is Power BI Premium? , How to purchase Power BI Premium.

 

Please do mask sensitive data before uploading.

 

Thanks for your understanding and support.

 

Best Regards,

Dedmon Dai

AllisonKennedy
Super User
Super User

@a4  Are you simply multiplying a daily rate times number of days in the year? I feel like this could be done with a much simpler DAX if you have a proper DimDate table, rather than a summarized Year-Days table. 

https://allisonkennedycv.blogspot.com/2020/04/dimdate-what-why-and-how.html

 

In your DimDate table you'll want to add the [Number of Days in Year] column. You could do this in the Query Editor by adding Start of Year, End of Year, and then doing Subtract Days, all from the Date button in the Add Column tab in the ribbon. 🙂 

 

If that doesn't help, please provide more info. 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

amitchandak
Super User
Super User

@a4 , this formula needs to be revisited.

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. Can you please explain the formula functionally with an example.

Appreciate your Kudos.

 

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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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