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
Anonymous
Not applicable

Return a single value from a column based on a measure DAX

Hello ,
I am trying to replace the unassigned value in type column with the value of type of max program. This need to be done on calculated column As showing in New Type Colum required.

ID, Program,Type, New Type

117

32

#

MST

117

679

MST

MST

 

Here is the DAX code:

New Type =

//Get Max Program

var MaxProgram = MAX('Table22'[Program])

 

//Get Max Program by ID

var MaxProgramByID = CALCULATE(MaxProgram,ALLEXCEPT('Table22','Table22'[ID]))

 

//Get The type of Max Program by ID

var NewType=SUMMARIZE (FILTER('Table22',('Table22'[Program]=MaxProgramByID)),'Table22'[Program],'Table22'[ID])

 

Return

 

if('Table22'[Type]="#",NewType,'Table22'[Type])

Anyhow, it gives this error "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value."

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Please try code as below to create a calculated column.

New Type = 
//Get Max Program by ID
VAR MaxProgramByID =
    CALCULATE ( MAX ( 'Table22'[Program] ), ALLEXCEPT ( 'Table22', 'Table22'[ID] ) ) //Get The type of Max Program by ID
VAR NewType =
    MAXX (
        FILTER ( ALLEXCEPT ( Table22, Table22[ID] ), Table22[Program] = MaxProgramByID ),
        [Type]
    )
RETURN
    IF ( 'Table22'[Type] = "#", NewType, 'Table22'[Type] )

Result is as below.

vrzhoumsft_0-1683711270879.png

 

Best Regards,
Rico Zhou

 

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

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , try like

 

//Get The type of Max Program by ID

var NewType=SUMMARIZE (FILTER('Table22',('Table22'[Program]=MaxProgramByID)),'Table22'[Program])

Return
if('Table22'[Type]="#",maxx(NewType,[Program]),max('Table22'[Type]))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

New DAX code.jpg

Hi @Anonymous ,

 

Please try code as below to create a calculated column.

New Type = 
//Get Max Program by ID
VAR MaxProgramByID =
    CALCULATE ( MAX ( 'Table22'[Program] ), ALLEXCEPT ( 'Table22', 'Table22'[ID] ) ) //Get The type of Max Program by ID
VAR NewType =
    MAXX (
        FILTER ( ALLEXCEPT ( Table22, Table22[ID] ), Table22[Program] = MaxProgramByID ),
        [Type]
    )
RETURN
    IF ( 'Table22'[Type] = "#", NewType, 'Table22'[Type] )

Result is as below.

vrzhoumsft_0-1683711270879.png

 

Best Regards,
Rico Zhou

 

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

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.