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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It 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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.