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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
QwertyMartijn
Helper II
Helper II

How to create custom column based on value in cell?

Hi guys,

 

My data has the following structure:

IDQuestionAnswer
1Contractor?Firm A
1Completed work?Yes
1Paid?No
2Contractor?Firm B
2Completed work?No
2Paid?No

 

Basically i have data on answers from a questionaire, and questions are grouped by ID. However, i want to add a 4th column, per ID that displays the name of the contractor, to nicely visualize and work with the data.

 

Like this:

IDQuestionAnswerQuestions from contractor:
1Contractor?Firm AFirm A
1Completed work?YesFirm A
1Paid?NoFirm A
2Contractor?Firm BFirm B
2Completed work?NoFirm B
2Paid?NoFirm B

 

Any help would be greatly appreciated!

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

pls try this

Column = 
VAR t1 = [ID]
RETURN MAXX(
FILTER(ALL('Table'),'Table'[ID]=t1&&'Table'[Question]="Contractor?"),[Answer])

Screenshot_3.png

View solution in original post

3 REPLIES 3
Ahmedx
Super User
Super User

pls try this

Column = 
VAR t1 = [ID]
RETURN MAXX(
FILTER(ALL('Table'),'Table'[ID]=t1&&'Table'[Question]="Contractor?"),[Answer])

Screenshot_3.png

This totally helped! Thank you so much. Could you explain the code so that i can learn what is does?

Your DAX code is used to create a calculated column in Power BI or Power Pivot, based on specified conditions and operations. Let's break it down step by step:

1)  VAR t1 = [ID]: In this line, a temporary variable t1 is created, which holds the value of the current row's [ID] column. This is done to avoid repeated access to [ID] in subsequent operations.

2)  FILTER(ALL('Table'), 'Table'[ID] = t1 && 'Table'[Question] = "Contractor?"): Here, the FILTER function is used to filter the 'Table' based on certain conditions. ALL('Table') is used to ignore any existing filters on the table and work with it entirely. The filtering conditions involve comparing the [ID] column with the temporary variable t1 and the [Question] column with the text "Contractor?".

3) MAXX(..., [Answer]): The MAXX function is applied to the filtered result and calculates the maximum value of the [Answer] column within the filtered table.

As a result, for each row in the [ID] column, the maximum value of the [Answer] column satisfying the filtering conditions based on [ID] and [Question] will be computed.

The code appears logical and performs the described actions. However, it's worth considering performance implications, as using FILTER(ALL(...)) can potentially impact performance, especially with large datasets.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.