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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Calculated column based on information of 3 other columns

Hello community members, 

 

I have the following question. 

 

I need a calculated column that provides me the  following information. 

Each unique client (UNIEKE_CLIENTCODE) can have 2 or more different 'SegmentNew' codes. Now I would like to have a calculated column that states in each row the SegmentNew code for the client that has the largest value in the column Year. (I tried to visualize the column I need in the table below). 

 

Can someone help me with this issue? 

 

Hope to hear soon from you! 

 

Best regards, Sander

 

UNIEKE_CLIENTCODEAgeYearSegmentNewCalculated column I need
Ax65< 750,911A Begeleiding2A
Ax65< 751,52A2A
Ax11< 752,561A Begeleiding1A Begeleiding
Ax11< 751,272A1A Begeleiding
AxF5< 750,661A Begeleiding1B
AxF5< 752,241B1B
1 ACCEPTED SOLUTION

@Anonymous,

 

Try this:

 

SegmentNew Max Year = 
// if a client has a SegmentNew, 2A and 3A (and the 3A has the max year), the result should be 2A
VAR vMaxYear =
    CALCULATE (
        MAX ( Table1[Year] ),
        ALLEXCEPT ( Table1, Table1[UNIEKE_CLIENTCODE] )
    )
VAR vSegmentNew =
    CALCULATE (
        MAX ( Table1[SegmentNew] ),
        ALLEXCEPT ( Table1, Table1[UNIEKE_CLIENTCODE] ),
        Table1[Year] = vMaxYear
    )
VAR vRowCount2A =
    CALCULATE (
        COUNTROWS ( Table1 ),
        ALLEXCEPT ( Table1, Table1[UNIEKE_CLIENTCODE] ),
        Table1[SegmentNew] = "2A"
    )
VAR vResult =
    IF (
        NOT ISBLANK ( vSegmentNew )
            && vRowCount2A > 0
            && vSegmentNew = "3A",
        "2A",
        vSegmentNew
    )
RETURN
    vResult

 

DataInsights_0-1626007374556.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
DataInsights
Super User
Super User

@Anonymous,

 

Try this calculated column:

 

SegmentNew Max Year = 
VAR vMaxYear =
    CALCULATE (
        MAX ( Table1[Year] ),
        ALLEXCEPT ( Table1, Table1[UNIEKE_CLIENTCODE] )
    )
VAR vResult =
    CALCULATE (
        MAX ( Table1[SegmentNew] ),
        ALLEXCEPT ( Table1, Table1[UNIEKE_CLIENTCODE] ),
        Table1[Year] = vMaxYear
    )
RETURN
    vResult

 

DataInsights_0-1625751905936.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Hi @DataInsights , 

 

This calculated column works perfect!

 

Just one additional question. In the column SegmentNew, there is one particular code (3A) that should be excluded in the formula (and the results in the calculated formula). In other words, if a unique client has a Segment New, 2A and 3A (and the 3A has the max year), the result should be 2A...  

 

Easy to insert this in the formula? 

 

Best regards, Sander

@Anonymous,

 

Try this:

 

SegmentNew Max Year = 
// if a client has a SegmentNew, 2A and 3A (and the 3A has the max year), the result should be 2A
VAR vMaxYear =
    CALCULATE (
        MAX ( Table1[Year] ),
        ALLEXCEPT ( Table1, Table1[UNIEKE_CLIENTCODE] )
    )
VAR vSegmentNew =
    CALCULATE (
        MAX ( Table1[SegmentNew] ),
        ALLEXCEPT ( Table1, Table1[UNIEKE_CLIENTCODE] ),
        Table1[Year] = vMaxYear
    )
VAR vRowCount2A =
    CALCULATE (
        COUNTROWS ( Table1 ),
        ALLEXCEPT ( Table1, Table1[UNIEKE_CLIENTCODE] ),
        Table1[SegmentNew] = "2A"
    )
VAR vResult =
    IF (
        NOT ISBLANK ( vSegmentNew )
            && vRowCount2A > 0
            && vSegmentNew = "3A",
        "2A",
        vSegmentNew
    )
RETURN
    vResult

 

DataInsights_0-1626007374556.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

@DataInsights thanks for your help! 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.