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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
MintuBaruah
Helper III
Helper III

Dax optimization

Hi @all,

 

The below logics are taking a long time to execute.
Please help optimize these formulas.

 

imgpsh_fullsize_anim (1).jpgimgpsh_fullsize_anim.jpg

 

Thank you

2 REPLIES 2
amitchandak
Super User
Super User

@MintuBaruah , Can you please paste formulas in text format

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

Hi @amitchandak,

 

Below are the formulas in text format: 

A_TCPU =
var _C= CALCULATE(SELECTEDVALUE('Aggregated by VM'[CPU])) * ((100-[CPU_Rightizing_% Value])/100)

Return
IF(SELECTEDVALUE('Aggregated by VM'[Max CPU])>0 && SELECTEDVALUE('Aggregated by VM'[Max CPU])<[CPU_Max_Utilization Threshold Value],_C,SELECTEDVALUE('Aggregated by VM'[CPU]))

 

m_cpumatch =
var _cpu ='Aggregated by VM'[A_TCPU]

var tableFiltered=
TOPN(1,CALCULATETABLE('Price List',Filter('Price List','Price List'[CORE]>=_cpu && 'Price List'[Supported]="YES" &&'Price List'[Location] ='Aggregated by VM'[Location] ) ),'Price List'[CORE],ASC)

// var tableFiltered=
// TOPN(1,CALCULATETABLE('Price List',KEEPFILTERS('Price List'[CORE]>=_cpu && 'Price List'[Supported]="YES" &&'Price List'[Location] ='Aggregated by VM'[Location] ) ),'Price List'[CORE],ASC)


Return
SUMX(tableFiltered,[CORE])/COUNTX(tableFiltered,[CORE])

 

In the RI_price Target Instance match and Location is used

Measure 1:
3yr RI_price = 
VAR Price_per_hour = 
LOOKUPVALUE (
    'Price List'[THREE YEAR RESERVED PRICE WITH AHB in $ per hour],
    'Price List'[INSTANCE NAME], 'Aggregated by VM'[Target_Instance_type],
    'Price List'[Location], 'Aggregated by VM'[Location]
)
VAR no_ofhours  = 
    //CALCULATE ( SELECTEDVALUE ( 'Aggregated by VM'[on_demand_hours] ) )
    MAX('Aggregated by VM'[on_demand_hours])
RETURN 
Price_per_hour * no_ofhours


+++
Measure 2: 
Target_Instance_type = 
VAR _cpu = 'Aggregated by VM'[cpu_instancmatch]
VAR _memory = 'Aggregated by VM'[m_memorymatch]
VAR tbl_memorymatch_bycpu =
    TOPN (
        1,
        CALCULATETABLE (
            'Price List',
            FILTER (
                'Price List',
                'Price List'[CORE] = _cpu
                    && 'Price List'[RAM (GB)Rounded] = _memory
                    && 'Price List'[Supported] = "YES"
            )
        ),
        'Price List'[INSTANCE NAME], ASC
    )
RETURN
    SUMMARIZE ( tbl_memorymatch_bycpu, [INSTANCE NAME] )



+++

Measure 3:
Location = 

var _region=CALCULATE(SELECTEDVALUE('Aggregated by VM'[region]))
var tbl_locationmatch=
TOPN(1,CALCULATETABLE('Regions_Location',Filter('Regions_Location','Regions_Location'[armRegionName]=_region) ),'Regions_Location'[location],ASC)

Return
IF(ISBLANK(SUMMARIZE(tbl_locationmatch,Regions_Location[location])),_region,SUMMARIZE(tbl_locationmatch,Regions_Location[location]))

 

cpu_instancmatch = 

var _cpumatch =LOOKUPVALUE('Price List'[INSTANCE NAME],'Price List'[CORE],'Aggregated by VM'[m_cpumatch])
var _memorymatch =LOOKUPVALUE('Price List'[INSTANCE NAME],'Price List'[RAM(GiB)],'Aggregated by VM'[m_memorymatch])
var _cpu='Aggregated by VM'[m_cpumatch]
var _memory='Aggregated by VM'[m_memorymatch]


var tbl_cpumatch_bycpu=
TOPN(1,CALCULATETABLE('Price List',Filter('Price List','Price List'[CORE]>=_cpu && 'Price List'[RAM (GB)Rounded]=_memory && 'Price List'[Supported]="YES" &&'Price List'[Location] ='Aggregated by VM'[Location]) ),'Price List'[CORE],ASC)

var tbl_cpumatch_bymemory=
TOPN(1,CALCULATETABLE('Price List',Filter('Price List','Price List'[CORE]=_cpu && 'Price List'[RAM (GB)Rounded]>=_memory && 'Price List'[Supported]="YES" &&'Price List'[Location] ='Aggregated by VM'[Location]) ),'Price List'[CORE],ASC)

var _c1=SUMX(tbl_cpumatch_bycpu,[CORE])/COUNTX(tbl_cpumatch_bycpu,[CORE])
var _c2=SUMX(tbl_cpumatch_bymemory,[CORE])/COUNTX(tbl_cpumatch_bymemory,[CORE])


Return
if(ISBLANK(_c1),_c2,_c1)

 

Thanks.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.