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.
Hello everyone, I wante to post this in order to improve my skills and get a better understanding of Power BI.
The problem I solved is create a calculated column that concatenates other columns that have written one product name, so we have column 1 = product 1, column 2 = product 2... until 5 in my case. The tricky part is that I want to display the result in alphabetic order to be able to do some calculations based on the columns without having duplicated data because the name of the products are not ordered at the beginning.
So this is the code I created:
cadena productos ordenados =
var p1 = 'Table'[Product 1]
return
var p2 = 'Table'[Product 2]
return
var p3 = 'Table'[Product 3]
return
var p4 = 'Table'[Product 4]
return
var p5 = 'Table'[Product 5]
return
var word5 =
MAX(
MAX(
MAX(
MAX(
p1;
p2
);
p3
);
p4
);
p5
)
return
var word4 =
MAX(
MAX(
MAX(
MAX(
IF(p1=word5;BLANK();p1);
IF(p2=word5;BLANK();p2)
);
IF(p3=word5;BLANK();p3)
);
IF(p4=word5;BLANK();p4)
);
IF(p5=word5;BLANK();p5)
)
return
var word3 =
MAX(
MAX(
MAX(
MAX(
IF(OR(p1=word5;p1=word4);BLANK();p1);
IF(OR(p2=word5;p2=word4);BLANK();p2)
);
IF(OR(p3=word5;p3=word4);BLANK();p3)
);
IF(OR(p4=word5;p4=word4);BLANK();p4)
);
IF(OR(p5=word5;p5=word4);BLANK();p5)
)
return
var word2 =
MAX(
MAX(
MAX(
MAX(
IF(OR(p1=word3;OR(p1=word5;p1=word4));BLANK();p1);
IF(OR(p2=word3;OR(p2=word5;p2=word4));BLANK();p2)
);
IF(OR(p3=word3;OR(p3=word5;p3=word4));BLANK();p3)
);
IF(OR(p4=word3;OR(p4=word5;p4=word4));BLANK();p4)
);
IF(OR(p5=word3;OR(p5=word5;p5=word4));BLANK();p5)
)
return
var word1 =
MAX(
MAX(
MAX(
MAX(
IF(OR(p1=word2;OR(p1=word3;OR(p1=word5;p1=word4)));BLANK();p1);
IF(OR(p2=word2;OR(p2=word3;OR(p2=word5;p2=word4)));BLANK();p2)
);
IF(OR(p3=word2;OR(p3=word3;OR(p3=word5;p3=word4)));BLANK();p3)
);
IF(OR(p4=word2;OR(p4=word3;OR(p4=word5;p4=word4)));BLANK();p4)
);
IF(OR(p5=word2;OR(p5=word3;OR(p5=word5;p5=word4)));BLANK();p5)
)
return
CONCATENATE(
word1;
CONCATENATE(
IF(ISBLANK(word1);BLANK();", ");
CONCATENATE(
word2;
CONCATENATE(
IF(ISBLANK(word2);BLANK();", ");
CONCATENATE(
word3;
CONCATENATE(
IF(ISBLANK(word3);BLANK();", ");
CONCATENATE(
word4;
CONCATENATE(
IF(ISBLANK(word4);BLANK();", ");
word5
)
)
)
)
)
)
)
)
I think this code can be improved with maybe virtual tables but I don't know yet how to use them properly. I will be happy to receive any feedback from you.
Thank you!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
106 | |
94 | |
77 | |
65 | |
53 |
User | Count |
---|---|
145 | |
105 | |
104 | |
90 | |
63 |