cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mayank08 Member
Member

DAX Formula is very slow

Final Pain Car Aug =
IF (
[#Pain Rank Aug] = 22,
UNICHAR ( 128665 ),
IF (
[#Pain Rank Aug] = 21,
UNICHAR ( 128665 ),
IF (
[#Pain Rank Aug] = 20,
UNICHAR ( 128665 ),
IF (
[#Pain Rank Aug] = 19,
UNICHAR ( 128665 ),
IF (
[#Pain Rank Aug] = 18,
UNICHAR ( 128665 ),
IF (
[#Pain Rank Aug] = 17,
"_" & "_",
IF (
[#Pain Rank Aug] = 16,
"_" & "_"
& UNICHAR ( 128665 ),
IF (
[#Pain Rank Aug] = 15,
"_" & "_"
& "_"
& UNICHAR ( 128665 ),
IF (
[#Pain Rank Aug] = 14,
"_" & "_"
& "_"
& "_"
& UNICHAR ( 128665 ),
IF (
[#Pain Rank Aug] = 13,
"_" & "_"
& "_"
& "_"
& "_"
& UNICHAR ( 128665 ),
IF (
[#Pain Rank Aug] = 12,
"_" & "_"
& "_"
& "_"
& "_"
& "_"
& UNICHAR ( 128665 ),
IF (
[#Pain Rank Aug] = 11,
"_" & "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& UNICHAR ( 128665 ),
IF (
[#Pain Rank Aug] = 10,
"_" & "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& UNICHAR ( 128665 ),
IF (
[#Pain Rank Aug] = 9,
"_" & "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& UNICHAR ( 128665 ),
IF (
[#Pain Rank Aug] = 8,
"_" & "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& UNICHAR ( 128665 ),
IF (
[#Pain Rank Aug] = 7,
"_" & "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& UNICHAR ( 128665 ),
IF (
[#Pain Rank Aug] = 6,
"_" & "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& UNICHAR ( 128661 ),
IF (
[#Pain Rank Aug] = 5,
"_" & "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& UNICHAR ( 128661 ),
IF (
[#Pain Rank Aug] = 4,
"_" & "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& UNICHAR ( 128661 ),
IF (
[#Pain Rank Aug] = 3,
"_" & "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& UNICHAR ( 128665 ),
IF (
[#Pain Rank Aug] = 2,
"_" & "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& UNICHAR ( 128659 ),
IF (
[#Pain Rank Aug] = 1,UNICHAR ( 128666 ),
"_" & "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& "_"
& UNICHAR ( 128663 )

)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)

 

This code take hours to run. 

1 ACCEPTED SOLUTION

Accepted Solutions
BM4291 Regular Visitor
Regular Visitor

Re: DAX Formula is very slow

As suggested already SWITCH() will likely be your friend here.

 

Final Pain Car Aug = 
VAR i = [#Pain Rank Aug]
RETURN
SWITCH(i,
 1, UNICHAR(128666) & REPT("_", 12) & UNICHAR(128665),
 2, REPT("_", 16) & UNICHAR(128659)
)

 

 

The above is much neater and would imagine a touch more performant, obviously you'd need to expand and may be able to apply additional logic to how many '_' you're inserting.

2 REPLIES 2
NickNg278 Established Member
Established Member

Re: DAX Formula is very slow

@mayank08,

Have you considered to rewrite your DAX using SWITCH() statement instead? It might improve performance

BM4291 Regular Visitor
Regular Visitor

Re: DAX Formula is very slow

As suggested already SWITCH() will likely be your friend here.

 

Final Pain Car Aug = 
VAR i = [#Pain Rank Aug]
RETURN
SWITCH(i,
 1, UNICHAR(128666) & REPT("_", 12) & UNICHAR(128665),
 2, REPT("_", 16) & UNICHAR(128659)
)

 

 

The above is much neater and would imagine a touch more performant, obviously you'd need to expand and may be able to apply additional logic to how many '_' you're inserting.