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

Create a table using DAX

Hi, 

I need to create a calculated table based on which customer name is manually added to a CustomerKeyFilter.

I'm trying to add three columns from table1 [CustomerKey], [QuestionId], [Answer] and three from table2 [GroupName], [WorkSpace], [QuestionLabel].

NewTable = 
VAR CustomerKeyFilter = "CustomerName"
RETURN
ADDCOLUMNS (
FILTER ( 'Table1', 'Table1'[CustomerKey] = CustomerKeyFilter ),
"QuestionId", 'Table1'[QuestionId],
"Answer", 'Table1'[Answer],
"WorkSpace",
CALCULATE (
MAXX (
FILTER ( 'Table2', RELATED('Table2'[id]) = RELATED('Table1'[QuestionId]) ),
'Table2'[WorkSpace]
)
),
"GroupName",
CALCULATE (
MAXX (
FILTER ( 'Table2', RELATED('Table2'[id]) = RELATED('Table1'[QuestionId]) ),
'Table2'[GroupName]
)
),
"QuestionLabel",
CALCULATE (
MAXX (
FILTER ( 'Table2', RELATED('Table2'[id]) = RELATED('Table1'[QuestionId]) ),
'Table2'[QuestionLabel]
)
)
)

It produces the following error:

The column 'Table2[id]' either doesn't exist or doesn't have a relationship to any table available in the current context.

The red squiggly line under 'Table1'[QuestionId] states:

Parameter is not the correct type.

Both columns, 'Table1'[QuestionId] and 'Table2'[id], are the correct names, they both exist and both data types are text.

The relationship between the two tables, via these two columns, is Many to one with a single cross-filter direction.

 

I've been looking for what seems like an eternity to find a solution which I can't seem to find.
I can't see what I'm doing wrong and as such, not sure how to fix it. Can someone help please.

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

Hi, I think I've created the calculated table but I'm unsure if it meets the 'desired result' screenshots posted.

Here's the DAX:

NewTable2 = 
VAR CustomerKeyFilter = "CustomerName2"
RETURN
    ADDCOLUMNS (
        FILTER ( 'Table1', 'Table1'[CustomerKey] = CustomerKeyFilter ),
        "WorkSpace", RELATED('Table2'[WorkSpace] ),
        "GroupName", RELATED(Table2[GroupName] ),
        "QuestionLabel", RELATED('Table2'[QuestionLabel]  )
    )

 Let me know if that moves you on a bit further.

View solution in original post

9 REPLIES 9
HotChilli
Super User
Super User

Hi, I think I've created the calculated table but I'm unsure if it meets the 'desired result' screenshots posted.

Here's the DAX:

NewTable2 = 
VAR CustomerKeyFilter = "CustomerName2"
RETURN
    ADDCOLUMNS (
        FILTER ( 'Table1', 'Table1'[CustomerKey] = CustomerKeyFilter ),
        "WorkSpace", RELATED('Table2'[WorkSpace] ),
        "GroupName", RELATED(Table2[GroupName] ),
        "QuestionLabel", RELATED('Table2'[QuestionLabel]  )
    )

 Let me know if that moves you on a bit further.

This worked perfectly, thank you so much!

HotChilli
Super User
Super User

Can you change the access please so that i don't have to sign in?

Done

HotChilli
Super User
Super User

Put the pbix on a 3rd party site (a legit one) and post the link please.

v-yifanw-msft
Community Support
Community Support

Thank @HotChilli  for your prompt reply.

Hi @Nerf_Herder  ,

May I ask if your problem has been solved. If the problem is not yet solved, please feel free to ask us a question. Can you provide some example data such as detailed data (without sensitive information) and your relationships. This would allow us to better reproduce and solve the problem you are experiencing.

How to Get Your Question Answered Quickly - Microsoft Fabric Community

If it does not help, please provide more details with your desired out put and pbix file without privacy information.

 

Best Regards,

Ada Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

HotChilli
Super User
Super User

Can you post some sample data (just a few rows from each table please) and show what your desired result is.

It looks like there's too many RELATED keywords in there.

Can you post a picture of the relationship just to make sure I can understand what table keys are?

Apologies for the delayed response, I've been AFW. Below is the sample data and desired results. I've put it all in a sample pbix file but I can't upload it here.

 

Table1:

idCustomerKeyUIDQuestionIdAnswer
1392c747-42e7-4ff2-82e9-63eb973a9396CustomerName21392c747-42e7-4ff2-82e9-63eb973a9396/CustomerName26f5e51c8-b9c4-4840-b2da-c996d9e859f1Answer1
4cde4441-2f5c-4d91-9a07-9dc4d61be1e5CustomerName34cde4441-2f5c-4d91-9a07-9dc4d61be1e5/CustomerName3320c927d-cf51-4c10-bdb7-ab7283061226Answer2

 

Table2:

idWorkSpaceGroupNameQuestionLabelDesiredAnswer
534b0055-1b4d-4f34-8b42-ea933f78dc12Workspace1GroupName1QuestionLabel1DesiredAnswer1
320c927d-cf51-4c10-bdb7-ab7283061226Workspace1GroupName2QuestionLabel2DesiredAnswer2
6f5e51c8-b9c4-4840-b2da-c996d9e859f1Workspace1GroupName3QuestionLabel3DesiredAnswer3
d39d7fd3-2d82-4fb2-982d-47262ef20e0bWorkspace1GroupName4QuestionLabel4DesiredAnswer4

 

Nerf_Herder_6-1716306688853.png

 

Desired Results:

Nerf_Herder_2-1716306241594.png

Slicer Selected:

Nerf_Herder_5-1716306388206.png

Treemap Selected:

Nerf_Herder_3-1716306281721.png

Treemap & Slicer Selected:

Nerf_Herder_4-1716306324083.png

 

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.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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