Forum Discussion

RENJITH_R_S's avatar
RENJITH_R_S
Resolver II
5 years ago
Solved

Dax Help : Conditional Index

Hello   Could you please help me to create this condition index column see the example   Name       Index A                 1 B      C   A                 2 B A                 3 A        ...
  • PhilipTreacy's avatar
    5 years ago

    Hi RENJITH_R_S 

    Download sample PBIX file with this code.

    This works in Power Query

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclSK1YlWcgKTzmASWcQRRsYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t]),
        #"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
        #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each if [Name] = "A" then List.Count(List.Select(List.FirstN(#"Added Index"[Name], [Index]), each _ = "A")) else ""),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
    in
        #"Removed Columns"

     

    I'll see if I can do it in DAX too.

    Regards

    Phil