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
flyingfox
Regular Visitor

Looking for records where two variables are swapped

Hi, I am trying to figure out how to implement this scenario with DAX.

Consider the following matrix with three columns

idparametercost

AB

Parameter 1

10

AC

Parameter 2

20

AD

Parameter 3

15

CA

Parameter 4

40

EF

Parameter 6

67

FE

Parameter 7

80

EF

Parameter 8

45

GA

Parameter 9

45

CA

Parameter 5

52

 

The ID column is the concatenation of two variables that can be combined. I would like to find in the table all the records in which the two variables are swapped among each other.

The final result needs to be

idparametercost

AC

Parameter 2

20

CA

Parameter 4

40

CA

Parameter 5

52

EF

Parameter 6

67

FE

Parameter 7

80

EF

Parameter 8

45

Thank you for your support

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @flyingfox 

 

You can try the following methods.

Column:

id2 = RIGHT('Table'[id],1)&LEFT('Table'[id],1)

vzhangti_0-1653273692106.png

Table:

New Table = UNION(VALUES('Table'[id]),VALUES('Table'[id2]))

vzhangti_1-1653273763364.png

Measure:

Count id =
CALCULATE (
    COUNT ( 'New Table'[id] ),
    FILTER ( ALL ( 'New Table' ), [id] = SELECTEDVALUE ( 'New Table'[id] ) )
)
Measure = IF([Count id]=1,0,1)

vzhangti_2-1653273821981.png

Drag Measure into the view to be displayed and set it equal to 1.

vzhangti_3-1653273882189.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
flyingfox
Regular Visitor

I set up the secondary key in the model. It works. Thank you

v-zhangti
Community Support
Community Support

Hi, @flyingfox 

 

You can try the following methods.

Column:

id2 = RIGHT('Table'[id],1)&LEFT('Table'[id],1)

vzhangti_0-1653273692106.png

Table:

New Table = UNION(VALUES('Table'[id]),VALUES('Table'[id2]))

vzhangti_1-1653273763364.png

Measure:

Count id =
CALCULATE (
    COUNT ( 'New Table'[id] ),
    FILTER ( ALL ( 'New Table' ), [id] = SELECTEDVALUE ( 'New Table'[id] ) )
)
Measure = IF([Count id]=1,0,1)

vzhangti_2-1653273821981.png

Drag Measure into the view to be displayed and set it equal to 1.

vzhangti_3-1653273882189.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Dear Team_Charlotte,

thank you so much for your valuable support. You undestood my issue and you almost got the result because, I am sorry, I did not mention that each record in the master Table is associated to a date. Therefore dragging your interesting Measure into the view to be displayed and setting it equal to 1, it does not produce the desidered results because the filter does not work due to the missing date in the New Table. Could you help me, please?   

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.

Top Solution Authors