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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Kudy
Helper I
Helper I

Dataset with 2 x tblCalendars and Calculation Group

Hi,

I need a dax code for Calculation Group that can Remove existing relationship from a measure. 
my Measure that has an existing relationship has USERELATIONSHIP function and I cannot remove that relationship through my Calculation Group.

My fact table has two date fields: OrderDate & ShipmentDate;
Kudy_1-1710618085739.png

- OrderDate has an active relationship with tblCalendar1 and inactive relationship with tblCalendar2, in order to compare [Sales] for two different dates;

Dax for measures:

Sales = SUM(tbl_InternetSales[SalesAmount]);
Sales2 =
CALCULATE(
    [Sales],
    ALL(tblCalendar1),
    USERELATIONSHIP(
        tbl_InternetSales[OrderDate],
        'tblCalendar2'[Date]
    )
)
Kudy_0-1710618068304.png
works perfectly!

Here is my problem starting ↓

- ShipmentDate has an inactive relationship with tblCalendar1 and tblCalendar2, so I could swith [Sales] measure to [Sales (by ShipmentDate)] in Calculation Groups. 

Kudy_2-1710618185716.png

Kudy_4-1710619518027.png

 

I think the problem is here in ALL. 

Kudy_3-1710619447682.png

 

Code above for Calculation Group:

By ShipmentDate =

VAR _filter_Sales_by_tblCalendar1Date_as_ShipmentDate =
CALCULATE(
    SELECTEDMEASURE(),
    USERELATIONSHIP(
        tbl_InternetSales[ShipmentDate],
        tblCalendar1[Date]
    )
)

VAR _filter_Sales_by_tblCalendar2Date_as_ShipmentDate =
CALCULATE(
    SELECTEDMEASURE(),
    ALL(tbl_InternetSales[OrderDate]),
    USERELATIONSHIP(
        tbl_InternetSales[ShipmentDate],
        tblCalendar2[Date]
    )
)

RETURN

IF(
    ISSELECTEDMEASURE([Sales2]),
    _filter_Sales_by_tblCalendar2Date_as_ShipmentDate,
    _filter_Sales_by_tblCalendar1Date_as_ShipmentDate
)

 

3 REPLIES 3
lbendlin
Super User
Super User

What was your reason for having two calendar tables?  

For comparison of two custom dates, eg March 1-3 vs  March 4-6

Make both of them disconnected (inactivate the relationships)  and use measures and TREATAS to find the data to compare.

Helpful resources

Announcements
Europe Fabric Conference

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.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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