cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
viitama Frequent Visitor
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

Accepted Solutions
Super User
Super User

Re: creating new columns conditionally

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 )
    )

 

View solution in original post

3 REPLIES 3
Super User
Super User

Re: creating new columns conditionally

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 )
    )

 

View solution in original post

viitama Frequent Visitor
Frequent Visitor

Re: creating new columns conditionally

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.

Super User
Super User

Re: creating new columns conditionally

@viitama

 

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

 

 

Helpful resources

Announcements
Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 60 members 1,000 guests
Please welcome our newest community members: