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
Anonymous
Not applicable

YTG (Year to Go) Measure does NOT work with active relationship with Calendar

Hello 

@Ashish_Mathur - I adopted your solution with YTG - thank you!

@Greg_Deckler  - just bought your DAX Cookbook! Love it!

 

Will you please help me with the measure I wrote for YTG (Year to Go)?

Relationship : Calendar 1 - db_forecast INactive

mira_abel_2-1596279970434.png

Visial Matrix - it works fine!

mira_abel_1-1596279584488.png

 

Page Filters: Month- Year  from Calendar 

Measure: see below

YTG_Fct = VAR JrnlType = SWITCH(TRUE(),

MONTH(MAX('Calendar'[AccPer_#date]))=01, "YFR02",

MONTH(MAX('Calendar'[AccPer_#date]))=02, "YFR03",

MONTH(MAX('Calendar'[AccPer_#date]))=03, "YFR04",

MONTH(MAX('Calendar'[AccPer_#date]))=04, "YFR05",

MONTH(MAX('Calendar'[AccPer_#date]))=05, "YFR06",

MONTH(MAX('Calendar'[AccPer_#date]))=06, "YFR07",

MONTH(MAX('Calendar'[AccPer_#date]))=07, "YFR08",

MONTH(MAX('Calendar'[AccPer_#date]))=08, "YFR09",

MONTH(MAX('Calendar'[AccPer_#date]))=09, "YFR10",

MONTH(MAX('Calendar'[AccPer_#date]))=10, "YFR11",

MONTH(MAX('Calendar'[AccPer_#date]))=11, "YFR12")

RETURN

CALCULATE(

    SUM(db_forecast[Base Amount])/1000,

    DATESBETWEEN('Calendar'[AccPer_#date],

    NEXTMONTH('Calendar'[AccPer_#date]),

    DATE(YEAR(MAX('Calendar'[AccPer_#date])),12,31)),

    FILTER(db_forecast,db_forecast[Journal Type] = JrnlType),

    FILTER(db_forecast,db_forecast[Year]=MAX('Calendar'[Year])))

 

This Measure has to look forward (opposite to YTD) till year end, so I use DATESBETWEEN. 

I also have to use SWITCH to filter out the Journal Type as we load updated versions YFR02...YFR12 of forecast every month for 3 years ahead (from Next Month) , each YFR.. journal is valid from  a reporting month onward. Because of the three year outlook - I had to introduce FILTER(db_forecast,db_forecast[Year]=MAX('Calendar'[Year]) to remove 2021-2022 from the forecast version.

 

Challenge: 

If I switch on the ACTIVE relationship between Calendar  - The measure YTG_Fct does NOT work

 
 
 

mira_abel_0-1596281110476.png

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I found the solution!

Wrapping the measure with another set of CALCULATE..., CROSSFILTER with option NONE deactivated the active relationship

 

Thank you all! Happy DAXing

https://community.powerbi.com/t5/Desktop/Deactivate-Relationship-in-a-measure/m-p/454772#M210708

 

Mira

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

You can tell it to use a specific relationship with the USERELATIONSHIP function 

https://docs.microsoft.com/en-us/dax/userelationship-function-dax#:~:text=USERELATIONSHIP%20uses%20e...

 

This way you can retain the active relationship for you other measures and use the inactive relationship for your new measure. 

Probably, something along the following lines of. If you ping me the PBIX file, I could get it working for you. 

YTG_Fct =
VAR JrnlType =
    SWITCH (
        TRUE (),
        MONTH ( MAX ( 'Calendar'[AccPer_#date] ) ) = 01, "YFR02",
        MONTH ( MAX ( 'Calendar'[AccPer_#date] ) ) = 02, "YFR03",
        MONTH ( MAX ( 'Calendar'[AccPer_#date] ) ) = 03, "YFR04",
        MONTH ( MAX ( 'Calendar'[AccPer_#date] ) ) = 04, "YFR05",
        MONTH ( MAX ( 'Calendar'[AccPer_#date] ) ) = 05, "YFR06",
        MONTH ( MAX ( 'Calendar'[AccPer_#date] ) ) = 06, "YFR07",
        MONTH ( MAX ( 'Calendar'[AccPer_#date] ) ) = 07, "YFR08",
        MONTH ( MAX ( 'Calendar'[AccPer_#date] ) ) = 08, "YFR09",
        MONTH ( MAX ( 'Calendar'[AccPer_#date] ) ) = 09, "YFR10",
        MONTH ( MAX ( 'Calendar'[AccPer_#date] ) ) = 10, "YFR11",
        MONTH ( MAX ( 'Calendar'[AccPer_#date] ) ) = 11, "YFR12"
    )
RETURN
    CALCULATE (
        SUM ( db_forecast[Base Amount] ) / 1000,
        DATESBETWEEN (
            'Calendar'[AccPer_#date],
            NEXTMONTH ( 'Calendar'[AccPer_#date] ),
            DATE ( YEAR ( MAX ( 'Calendar'[AccPer_#date] ) ), 12, 31 )
        ),
        FILTER ( db_forecast, db_forecast[Journal Type] = JrnlType ),
        FILTER ( db_forecast, db_forecast[Year] = MAX ( 'Calendar'[Year] ) ),
        USERELATIONSHIP ( 'Calendar'[AccPer_#date], db_forecast[AccPeriod] )
    )

 

Karlos. 

Anonymous
Not applicable

Hello 

 

Tried to add USERELATIONSHIP - it did NOT work unfortunately.

@Anonymous 

 

I will try to ping the file..

 

Thank you lots in advance,

Mira

Anonymous
Not applicable

Hello - not yet undresolved...
USERELATIONSHIP creates a relationship (even it is not a default from the data model)... 

I need a function that will deactivate for this measure the active datamodel relationship between the Calendar [Dates] and the datatable transaction dates. 
Although I don't fully understand why active relationship blocks the measure seeing future dates - Year to Go - till end of year... 

If anyone can help - it would be great!
Thank you lots

Mira

Anonymous
Not applicable

I found the solution!

Wrapping the measure with another set of CALCULATE..., CROSSFILTER with option NONE deactivated the active relationship

 

Thank you all! Happy DAXing

https://community.powerbi.com/t5/Desktop/Deactivate-Relationship-in-a-measure/m-p/454772#M210708

 

Mira

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