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

creating new columns conditionally

Hi, I'm struggling with references and conditions. Here is my table and I wan't te recreate Res column.

 

IDsubIDVolRes
Aaa1000ac
Aab250ac
Aac5000ac
Baa50ab
Bab6000ab
Bac300

ab

 

Res column is created by grouping by ID and selecting subID that has maximum Vol. Moving to Power BI from R where these reference seems logical, but here I can't get them to work at all.

 

Here is my try, but giving just blanks.

 

Res = 
    CALCULATE (
        SELECTEDVALUE ( subID ),
        FILTER ( ALLEXCEPT ( 'Table', ID ), Vol = MAX(Vol) )
    )

 

 

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

hi @viitama

 

Try the same pattern I gave you last time

 

Res =
VAR MaxFig =
    CALCULATE ( MAX ( 'Table'[Vol] ), ALLEXCEPT ( 'Table', 'Table'[ID] ) )
RETURN
    CALCULATE (
        VALUES ( 'Table'[subID] ),
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[ID] ), 'Table'[Vol] = MaxFig )
    )

 


Regards
Zubair

Please try my custom visuals

View solution in original post

3 REPLIES 3
Zubair_Muhammad
Community Champion
Community Champion

hi @viitama

 

Try the same pattern I gave you last time

 

Res =
VAR MaxFig =
    CALCULATE ( MAX ( 'Table'[Vol] ), ALLEXCEPT ( 'Table', 'Table'[ID] ) )
RETURN
    CALCULATE (
        VALUES ( 'Table'[subID] ),
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[ID] ), 'Table'[Vol] = MaxFig )
    )

 


Regards
Zubair

Please try my custom visuals

I had something like that, but it is giving me error "A table of multiple values was supplied where a single value was expected". Not sure why that fails. Actually change VALUES to SELECTEDVALUE and it works. Thanks.

@viitama

 

VALUES would throw an error if there are same sub IDs with Max Vol for a particular ID.

 

 


Regards
Zubair

Please try my custom visuals

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.