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
vjnvinod
Impactful Individual
Impactful Individual

Calculated column help

Hi All,

Below is my few calculated coloumns of a Table "Data" in the screenshot

Capture.PNG

 

I would like to create another calculated coloumn "Performance" based on below parameter

how to do this?

 

  Performance
TER MLO>95%Top
ANSR/TER Ratio>85%Top
Margin %>50%Top
NUI<2.4Top
AR<2.1Top
TI<4.5Top
TER MLO85% - 95%Average
ANSR/TER Ratio80% - 85%Average
Margin %45% - 50%Average
NUI2.4 - 2.7Average
AR2.1 - 2.3Average
TI4.5 - 5.0Average
TER MLO75% - 85%Below Average
ANSR/TER Ratio75% - 80%Below Average
Margin %40% - 45%Below Average
NUI2.7 - 3.0Below Average
AR2.3 - 2.5Below Average
TI5.0 - 5.5Below Average
TER MLO<75%Low
ANSR/TER Ratio<75%Low
Margin %<40%Low
NUI>3.0Low
AR>2.5Low
TI>5.5Low
1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @vjnvinod ,

According to my understand , you want to display Performance from another table for each Type in specific range, right?

 

You need to transform Performance Table firstly:

1. Add a LargeThan column and replace all blank values with 0.

2. Add a LessThan column and replace all blank values with 100%.

12.9.4.1.PNG

The whole M syntax is shown below:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fZJdC4IwFIb/yhh0ZzZzQ7ss6CLQgmVX5oXIkCAyoo+/3zzLeVrmnfC8nr0PvHlOs7UkabKjHj0+GAvVQkz0d9ZcaeHldLndy1kbkeX91NhQ/BVKy1t9upCJxYJhvD1sOlLNfY6vSwQCBLL+D+4LDGxbXYFMiWm7fKpbWavhxjFrg/FPELXmcMu0xhHTXHfWdO5H7ksSYAAwdCAY6O7tXZ+50FpEoi+3UufmRUZdPnE2HMdGIM3/3O28Ip0Jod3A28YuBDsxGAFHbQeOfyLf66oiaJQ0r5F1OSF3XRVnGKN1KeNir9t1KWPQgX5dSvSgeAM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Type = _t, Val = _t, Performance = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Type", type text}, {"Val", type text}, {"Performance", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "LargeThan", each if Text.StartsWith([Val],">") then Text.AfterDelimiter([Val],">") else  if Text.StartsWith([Val],"<") then Text.BeforeDelimiter([Val],"<") else Text.BeforeDelimiter([Val],"-")),
    #"Replaced Value" = Table.ReplaceValue(#"Added Custom","","0",Replacer.ReplaceValue,{"LargeThan"}),
    #"Added Custom1" = Table.AddColumn(#"Replaced Value", "LessThan", each if Text.StartsWith([Val],">") then Text.BeforeDelimiter([Val],">") else  if Text.StartsWith([Val],"<") then Text.AfterDelimiter([Val],"<") else Text.AfterDelimiter([Val],"-")),
    #"Replaced Value1" = Table.ReplaceValue(#"Added Custom1","","100%",Replacer.ReplaceValue,{"LessThan"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value1",{{"LargeThan", type number}, {"LessThan", type number}})
in
    #"Changed Type1"

 

 

Then you could add some calculated columns using the following DAX formula: (Take ANSR/TER and NUI as examples)

 

ANSR/TER Performance =
VAR _ansr = [ANSR/TER]
RETURN
    CALCULATE (
        MAX ( 'Performance Table'[Performance] ),
        FILTER (
            'Performance Table',
            'Performance Table'[Type] = "ANSR/TER Ratio"
                && 'Performance Table'[LessThan] >= _ansr
                && 'Performance Table'[LargeThan] <= _ansr
        )
    )
NUI Performance =
VAR _nui =
    VALUE ( RIGHT ( [NUI], 3 ) )
RETURN
    CALCULATE (
        MAX ( 'Performance Table'[Performance] ),
        FILTER (
            'Performance Table',
            'Performance Table'[Type] = "NUI"
                && 'Performance Table'[LessThan] >= _nui
                && 'Performance Table'[LargeThan] <= _nui
        )
    )

 

 

 My final Data table looks like this:

12.9.4.2.PNG

 

Please take a look at my pbix file here:

https://qiuyunus-my.sharepoint.com/:u:/g/personal/stephent01_qiuyunus_onmicrosoft_com/EfKAVPFPs41Ntm...

 


Did I answer your question ? Please kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your table and your problem.

 

Best Regards,
Eyelyn Qin

View solution in original post

1 REPLY 1
v-eqin-msft
Community Support
Community Support

Hi @vjnvinod ,

According to my understand , you want to display Performance from another table for each Type in specific range, right?

 

You need to transform Performance Table firstly:

1. Add a LargeThan column and replace all blank values with 0.

2. Add a LessThan column and replace all blank values with 100%.

12.9.4.1.PNG

The whole M syntax is shown below:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fZJdC4IwFIb/yhh0ZzZzQ7ss6CLQgmVX5oXIkCAyoo+/3zzLeVrmnfC8nr0PvHlOs7UkabKjHj0+GAvVQkz0d9ZcaeHldLndy1kbkeX91NhQ/BVKy1t9upCJxYJhvD1sOlLNfY6vSwQCBLL+D+4LDGxbXYFMiWm7fKpbWavhxjFrg/FPELXmcMu0xhHTXHfWdO5H7ksSYAAwdCAY6O7tXZ+50FpEoi+3UufmRUZdPnE2HMdGIM3/3O28Ip0Jod3A28YuBDsxGAFHbQeOfyLf66oiaJQ0r5F1OSF3XRVnGKN1KeNir9t1KWPQgX5dSvSgeAM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Type = _t, Val = _t, Performance = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Type", type text}, {"Val", type text}, {"Performance", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "LargeThan", each if Text.StartsWith([Val],">") then Text.AfterDelimiter([Val],">") else  if Text.StartsWith([Val],"<") then Text.BeforeDelimiter([Val],"<") else Text.BeforeDelimiter([Val],"-")),
    #"Replaced Value" = Table.ReplaceValue(#"Added Custom","","0",Replacer.ReplaceValue,{"LargeThan"}),
    #"Added Custom1" = Table.AddColumn(#"Replaced Value", "LessThan", each if Text.StartsWith([Val],">") then Text.BeforeDelimiter([Val],">") else  if Text.StartsWith([Val],"<") then Text.AfterDelimiter([Val],"<") else Text.AfterDelimiter([Val],"-")),
    #"Replaced Value1" = Table.ReplaceValue(#"Added Custom1","","100%",Replacer.ReplaceValue,{"LessThan"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value1",{{"LargeThan", type number}, {"LessThan", type number}})
in
    #"Changed Type1"

 

 

Then you could add some calculated columns using the following DAX formula: (Take ANSR/TER and NUI as examples)

 

ANSR/TER Performance =
VAR _ansr = [ANSR/TER]
RETURN
    CALCULATE (
        MAX ( 'Performance Table'[Performance] ),
        FILTER (
            'Performance Table',
            'Performance Table'[Type] = "ANSR/TER Ratio"
                && 'Performance Table'[LessThan] >= _ansr
                && 'Performance Table'[LargeThan] <= _ansr
        )
    )
NUI Performance =
VAR _nui =
    VALUE ( RIGHT ( [NUI], 3 ) )
RETURN
    CALCULATE (
        MAX ( 'Performance Table'[Performance] ),
        FILTER (
            'Performance Table',
            'Performance Table'[Type] = "NUI"
                && 'Performance Table'[LessThan] >= _nui
                && 'Performance Table'[LargeThan] <= _nui
        )
    )

 

 

 My final Data table looks like this:

12.9.4.2.PNG

 

Please take a look at my pbix file here:

https://qiuyunus-my.sharepoint.com/:u:/g/personal/stephent01_qiuyunus_onmicrosoft_com/EfKAVPFPs41Ntm...

 


Did I answer your question ? Please kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your table and your problem.

 

Best Regards,
Eyelyn Qin

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.