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
fjellfisk
Frequent Visitor

Creating calculated table that can have relationship

I need som help creating a dax expession for a calculated table

 

Scenario (simplified)
Dim Tables:
Employee (EmployeeID)
Date (DateID)
Fact:

Sales (EmployeeID, DateID, SalesAmt)

Measure:
Sales amount 


I want to create a calculated table that contains

EmployeeID, DateID, Sales Amount


With this new calculated table, I want to add relationships to the dim tables. When I try this, I get circular reference errors. I want to kind of disconnect the calculated table and then connect it again. My example is very simplified. The issue I have is that the measure is slow because of detailed calculation logic. So I want to go for longer processing time for the dataset and better perfomance for endusers.

 

 

5 REPLIES 5
fjellfisk
Frequent Visitor

The challenge for me is the measure for sales amount. the measure is like this:

Sales Amount=CALCULATE(SUM('Sales'[Amount]),FILTER(ALL('Date'), 'Date'[DateID<=MAX('Date'[DateID]) && 'Date'[DateID]>=MIN('Date'[DateID))


When using this Measure in the calculated table, I get circular reference when creating relationship between date and Sales table. My hope was to "disconnect" the measure so I can create this relationship.

Hi @fjellfisk ,

Not sure. Please try this measure:

Sales Amount =
CALCULATE (
    SUM ( 'Sales'[Amount] ),
    FILTER (
        'Date',
        'Date'[DateID] <= MAX ( 'Date'[DateID] )
            && 'Date'[DateID] >= MIN ( 'Date'[DateID] )
    ),
    ALLEXCEPT ( 'Date', 'Date'[DateID] )
)

If this doesn't work, can you provide a sanitized file for testing?

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

fjellfisk
Frequent Visitor

Thanks, will try this. my problem was that I got circular reference when adding relations. I thought I tried to run summarize on sales tbl, but I'll try again! 🙂 

 

Thank you! 😊

Hi @fjellfisk ,

Any update?

 

Best Regards,
Gao

Community Support Team

v-cgao-msft
Community Support
Community Support

Hi @fjellfisk ,

I created a sample file based on the description.

Sales:

vcgaomsft_0-1666849770689.png

Employee:

 

Employee = DISTINCT('Sales'[EmployeeID])

 

Date:

 

Date = CALENDAR(MIN('Sales'[DateID]),MAX('Sales'[DateID]))

 

Measure:

 

Sales amount = SUM('Sales'[SalesAmt])

 

Table:

 

Table = 
SUMMARIZE('Sales','Sales'[EmployeeID],'Sales'[DateID],"Sales Amount",[Sales amount])

 

vcgaomsft_1-1666849882626.png

relationships:

vcgaomsft_2-1666849916601.png

I am not sure if these cover your data, if not, please provide more details about the question and feel free to contact us.

If possible, you could also consider referencing the sales table in the PowerQuery Eidtor and using m-code to perform the calculations, but it's not clear what the logic is for this part of the measure. The advantage of this is that it only takes up resources when the data is refreshed and there are no circular reference errors

vcgaomsft_3-1666850365422.png

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

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.