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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
MattyH
Frequent Visitor

Help me fix my Variable syntax :D

Hey Guys

 

I've put together the following variable below.  It breaks down at the last step because I referenced a variable in the last calculate formula. I sort of understand that why this doesn't work but unsure of how to get it to work. I've seen some peeople put variables inside Calculate or Calculate around the entire variable but its confusing for a DAX n00b such as myself.

 

Is there a way I can write this (without creating another measure) to get the SCPTotalSiteSales to calculate properly?

 

Appreciate any help

 

 

SCP Equipment Allocation :=
VAR SiteLabourSalesTotal =
    IF (
        [Labour Sales] <> 0,
        CALCULATE (
            [Labour Sales],
            CostCentre[Facility] = "SCP",
            ScopeCodes[ScopeCodeLv2] = "Site"
        )
    ) // This section calculates the total LabourSales for SCP and Site only.
VAR SCPTotalSiteSales =
    IF (
        [Labour Sales] <> 0,
        CALCULATE (
            SiteLabourSalesTotal,
            REMOVEFILTERS ( Sales ),
            REMOVEFILTERS ( ProjectLevel ),
            REMOVEFILTERS ( CostCentre ),
            REMOVEFILTERS ( ScopeCodes ),
            VALUES ( Dates[Month & Year] ),
            VALUES ( ScopeCodes[ScopeCodeLv2] )
        )
    ) // THis calculates the total SCP site sales against all the rows
RETURN
    SCPTotalSiteSales

1 REPLY 1
MattyH
Frequent Visitor

Its all good. I figured it out. Just have to embed the variable within a variable.

 

 

SCP Equipment Allocation2 =
VAR SCPTotalSiteSales =
    IF (
        [Labour Sales] <> 0,
        CALCULATE (
            VAR SiteLabourSalesTotal =
                CALCULATE (
                    [Labour Sales],
                    CostCentre[Facility] = "SCP NDT Services",
                    ScopeCodes[ScopeCodeLv2] = "Site"
                ) // This section calculates the total LabourSales for SCP and Site only.
            RETURN
                SiteLabourSalesTotal,
            REMOVEFILTERS ( Sales ),
            REMOVEFILTERS ( ProjectLevel ),
            REMOVEFILTERS ( CostCentre ),
            REMOVEFILTERS ( ScopeCodes ),
            VALUES ( Dates[Month & Year] ),
            VALUES ( ScopeCodes[ScopeCodeLv2] )
        )
    ) // THis calculates the total SCP site sales against all the rows
RETURN
    SCPTotalSiteSales

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.