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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
navpienaar
Regular Visitor

Referencing one DAX measure in another

I know there are other ways of doing this, but I want to know if there is a way to do the following:

I want to reference Measure 1 in Measure 2

Measure 1 is OK and working

 

 

Measure 1:         vMax_Year_PY  = Max('SALES'[Year])-1

                Note:     Year is a separate field in the Sales table

                              I want to treat vMax_Year_PY  almost as a “global variable” in different measure functions…

 

Measure 2:        CALCULATE(SUM('Sales'[Sales]),'Sales'[Year] = vMax_Year_PY )

Is there any syntax to make this type of function work??

2 REPLIES 2
Zubair_Muhammad
Community Champion
Community Champion

@navpienaar

 

Try this one

 

Measure 2 =
VAR MyYear = [vMax_Year_PY]
RETURN
    CALCULATE (
        SUM ( 'Sales'[Sales] ),
        FILTER ( ALLSELECTED ( Sales[YEAR] ), 'Sales'[Year] = MyYear )
    )

Regards
Zubair

Please try my custom visuals

Hi Zubair

I am getting part of the correct answer with the following if I select a specific Year:

Sales PY =
VAR MyYear = [vMax_Year_PY]
RETURN CALCULATE ( SUM ( TRANS[Sales] ), FILTER ( ALL ( TRANS[YEAR] ), TRANS[YEAR] = MyYear ) )

 

However, it does not give me all the Sales for the Previous Year (all products), if in the there were no sales for specific products in the selected year.

 

Please see the image and Sandbox App in the link: https://drive.google.com/drive/folders/1ZPtPMgDm1CID4AnezDGsu49ve1vY0EtP?usp=sharing

https://drive.google.com/drive/folders/1ZPtPMgDm1CID4AnezDGsu49ve1vY0EtP?usp=sharing

 PrevYear.png

 

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.