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

Selected Value dax Query

I have this data but not sure on how to do the dax on this.

JuradoKevin14_0-1712813493628.png

Thank you on whoever can help me.

1 ACCEPTED SOLUTION

A measure doesn't create rows so you won't be able to have those tabular lists. If the calculated table on your end, doesnt  give you the correct order, you can just create two extra columns to kind of select the should be column values.

Sort2 = 
IFERROR ( VALUE ( NewTable[Sort] ), VALUE ( NewTable[Carrier] ) )

Carrier2 = 
IF (
    NewTable[Sort] = NewTable[Type],
    NewTable[Type],
    NewTable[Carrier]
)

danextian_0-1712919795742.png

 










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

9 REPLIES 9
danextian
Super User
Super User

Hi @JuradoKevin14 ,

 

SELECTEDVALUE won't work. You need to make the list physically appear in the model for every value in Type.  Assuming that the Carrier value is to be replaced by Type value, use this sample DAX calculated table.

NewTable =
VAR __TYPE =
    DISTINCT ( OriginalTable[Type] )
VAR __CROSSJOINED =
    SELECTCOLUMNS (
        FILTER (
            CROSSJOIN (
                __TYPE,
                SELECTCOLUMNS (
                    OriginalTable,
                    "Type2", OriginalTable[Type],
                    "Carrier", OriginalTable[Carrier]
                )
            ),
            [Type] <> [Type2]
        ),
        "Type", [Type],
        "Carrier", [Carrier]
    )
VAR __LETTER_CARRIER =
    ADDCOLUMNS ( __TYPE, "Carrier", [Type] )
RETURN
    UNION ( __LETTER_CARRIER, __CROSSJOINED )

danextian_0-1712822673420.png

 










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi sir thank you got it. but i am fixing the sort so that it would be in ascending order. but I cant seem to put it in the filter page? 

 

JuradoKevin14_0-1712844953328.png

JuradoKevin14_1-1712844995077.png

 

JuradoKevin14_2-1712845072900.png

 

Modidfy the calculated table formula to below to add a sort column. All Carrier values will have a blank sort while the rest will have 1.

NewTable =
VAR __TYPE =
    DISTINCT ( OriginalTable[Type] )
VAR __CROSSJOINED =
    SELECTCOLUMNS (
        FILTER (
            CROSSJOIN (
                __TYPE,
                SELECTCOLUMNS (
                    OriginalTable,
                    "Type2", OriginalTable[Type],
                    "Carrier", OriginalTable[Carrier]
                )
            ),
            [Type] <> [Type2]
        ),
        "Type", [Type],
        "Carrier", [Carrier],
        "Sort", 1
    )
VAR __LETTER_CARRIER =
    ADDCOLUMNS ( __TYPE, "Carrier", [Type], "Sort", BLANK () )
RETURN
    UNION ( __LETTER_CARRIER, __CROSSJOINED )

 










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

The sorting should be the same as the corresponding Carrier.

The shorting should be like this. 

JuradoKevin14_0-1712891273741.png

 

You're better off doing this in M that in DAX.  Below is the updated DAX calculated table formula but this returns the wrong order and won't change even if created as a new  table.

 

NewTable_ = 
VAR __TYPE =
    DISTINCT ( OriginalTable[Type] )
VAR __TYPE2 =
    DISTINCT (
        SELECTCOLUMNS (
            OriginalTable,
            "Type", [Type],
            "Carrier", [Type],
            "Sort", [Index]
        )
    )
VAR __CROSSJOINED =
    SELECTCOLUMNS (
        FILTER (
            CROSSJOIN (
                __TYPE,
                SELECTCOLUMNS (
                    OriginalTable,
                    "Type2", [Type],
                    "Carrier", [Carrier],
                    "Sort", [Index]
                )
            ),
            [Type] <> [Type2]
        ),
        "Type", [Type],
        "Sort", [Sort],
        "Carrier", [Carrier]
    )
VAR __LETTER_CARRIER =
    ADDCOLUMNS ( __TYPE, "Carrier", [Type] )
RETURN
    UNION ( __CROSSJOINED, __TYPE2 )

 

Here's the M code

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXJOLCrKTC1SMFSK1YlWckISMQKLOCOJGINFXJBETMAirkgipmARNyQRM6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Type = _t, Carrier = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Type", type text}, {"Carrier", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Table from Previous Step" = Table.AddColumn(#"Added Index", "Previous Step", each #"Added Index"),
    #"Expanded Previous Step" = Table.ExpandTableColumn(#"Table from Previous Step", "Previous Step", {"Type", "Carrier", "Index"}, {"Previous Step.Type", "Previous Step.Carrier", "Previous Step.Index"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Previous Step", each [Previous Step.Type] <> [Type]),
    #"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"Type", "Previous Step.Carrier", "Previous Step.Index"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns",{{"Previous Step.Index", "Index"}}),
    #"Appended Added Index to the Prev Step" = Table.Combine({#"Added Index", #"Renamed Columns"}),
    #"Removed Columns" = Table.RemoveColumns(#"Appended Added Index to the Prev Step",{"Carrier"}),
    #"Added Custom" = Table.AddColumn(#"Removed Columns", "Carrier", each if [Previous Step.Carrier] = null then [Type] else [Previous Step.Carrier]),
    #"Removed Columns1" = Table.RemoveColumns(#"Added Custom",{"Previous Step.Carrier"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns1",{"Type", "Carrier", "Index"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Reordered Columns",{{"Carrier", type text}}),
    #"Renamed Columns1" = Table.RenameColumns(#"Changed Type1",{{"Index", "Sort"}})
in
    #"Renamed Columns1"

 

danextian_0-1712913517982.png

 










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

I think i am havign trouble using this concept to incorporate to my existing data model. Is it possible to use it as a measure instead?

A measure doesn't create rows so you won't be able to have those tabular lists. If the calculated table on your end, doesnt  give you the correct order, you can just create two extra columns to kind of select the should be column values.

Sort2 = 
IFERROR ( VALUE ( NewTable[Sort] ), VALUE ( NewTable[Carrier] ) )

Carrier2 = 
IF (
    NewTable[Sort] = NewTable[Type],
    NewTable[Type],
    NewTable[Carrier]
)

danextian_0-1712919795742.png

 










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

The problem is i am using this table as dim to be connected to a fact table. so the relationship is many to many.. and also only A has data when it is connected becasue in the fact table the type is only shown. not the corresponding column which is the carrier. For example :

JuradoKevin14_0-1712928707993.png

 

@JuradoKevin14 

select the Type column and go to columntools and click on sort option, here you need to select Sort column. we basically specifying to use Sort column to sort Type column with this approach. 

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

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.