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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
bitbit
Helper I
Helper I

Error in DAX formula involving Variable & AverageX

Pls advise how to fix syntax error in below formula:

Prodvol per DL =
VAR
prodvol = CALCULATE(sum(data[Tons production],data[date])
VAR
DLavg = AVERAGEX(filter(FTE,FTE[Line]="Total direct manufacturing personnel"&&FTE[FTECat]="FTE Total"),'FTE'[Value])
)
RETURN
    if(
isblank(DLavg),"0",
divide(
prodvol,avgDL
)
)
5 REPLIES 5
Anonymous
Not applicable

 

Prodvol per DL =
VAR prodvol =
    CALCULATE ( SUM ( data[Tons production] ) )
VAR DLavg =
    AVERAGEX (
        FILTER (
            FTE,
            AND( 
           	FTE[Line] = "Total direct manufacturing personnel",
            	FTE[FTECat] = "FTE Total"
            )
        ),
        'FTE'[Value]
    )
RETURN
	DIVIDE ( prodvol, avgDL, 0 )

Please, do yourself a favour if you don't want to get stuck trying to figure out where you've messed up the syntax: ALWAYS format your code correctly according to the rules. If you have trouble, use www.daxformatter.com.

 

Best

Darek

 

Hi Darek,

 

Although syntax error is resolved, the calculated result is incorrect:

CountryActualBudgetPrior Year
CountryA293249282
CountryB500488483
CountryC481427445

 

Dataset "data", calculated production volume ytd Jun (NB: budget and prior year data includes all 12 months):

CountryActualBudgetPrior Year
CountryA481134308844088
CountryB139411588114259
CountryC174111842618101

 

Dataset "FTE", calculated average direct labour headcount ytd Jun (likewise, budget and prior year data includes all 12 months):

CountryActualBudgetPrior Year
CountryA134215761394
CountryB786806813
CountryC816921882

 

DAX formula should produce production volume per DL as follows:

CountryActualBudgetPrior Year
CountryA362732
CountryB182018
CountryC212021
Anonymous
Not applicable

Sorry, mate, I can't help you since I don't know anything about your model. I showed you where the syntax error was. That's all I could do. If you need to have some logic in your measures, you have to show all the details. I'm not able to solve an equation if I don't even know what it looks like.

 

Best

Darek

Hi Darek.  Pls refer to the sample pbix file in below link:

https://www.dropbox.com/s/3h85fs98rx4cq8l/sample.pbix?dl=0

 

Anonymous
Not applicable

Hi.

 

I'll have a look when I get a chance... But be prepared to answer questions.

 

Best

Darek

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.

Top Solution Authors