Forum Discussion
DYNAMIC FORMAT USING DAX FOR SLICER
- 6 years ago
GOT IT!!!
I took the initial code you sent that fixed the percentage values and switched it out with the new line of code but left the currency values as is. THIS IS THE CODE THAT WORKS. Thank you so much!!!
Sales$ (Table) =IF (ISCROSSFILTERED ( 'Parameter'[calculations] ),SWITCH (TRUE (),VALUES('Parameter'[calculations]) = "YoY%",SWITCH( TRUE(),ABS([Sales$ YoY%]) < 0.1, FORMAT([Sales$ YoY%]," 0.0%"),ABS([Sales$ YoY%]) < 1, FORMAT([Sales$ YoY%]," 0.0%"),FORMAT([Sales$ YoY%],"0%")),VALUES ( 'Parameter'[calculations] ) = "YoY Gap", RIGHT ( " $" & FORMAT ( [Sales$ YoY Gap], "0,0" ), 12 ),VALUES ( 'Parameter'[calculations] ) = "Current Year Actuals", RIGHT ( " $" & FORMAT ( [Sales$ CY], "0,0" ), 12 ),BLANK ()),BLANK ()) - 6 years ago
Add another space and change the 5 to 6.
Stunts schmunts. Try this:
Sales$ :=
IF (
ISCROSSFILTERED ( 'Parameter'[calculations] ),
SWITCH (
TRUE (),
VALUES ( 'Parameter'[calculations] ) = "YoY%", IF (
ABS ( [Sales$ YoY%] ) < 1,
RIGHT ( " " & FORMAT ( [Sales$ YoY%], "0.0%" ), 5 ),
FORMAT ( [Sales$ YoY%], "0%" )
),
VALUES ( 'Parameter'[calculations] ) = "YoY Gap", RIGHT ( " $" & FORMAT ( [Sales$ YoY Gap], "0,0" ), 12 ),
VALUES ( 'Parameter'[calculations] ) = "Current Year Actuals", RIGHT ( " $" & FORMAT ( [Sales$ CY], "0,0" ), 12 ),
BLANK ()
),
BLANK ()
)
You are on a roll! So the currency values have been FIXED and the percentages look good with only a very minor issue. See picture below:
- lbendlin6 years ago
Super User
Add another space and change the 5 to 6.
- cuohanele6 years ago
Helper I
That works! Thanks a bunch. This is the final DAX:
Sales$ (Table) :=
IF (
ISCROSSFILTERED ( 'Parameter'[calculations] ),
SWITCH (
TRUE (),
VALUES ( 'Parameter'[calculations] ) = "YoY%", IF (
ABS ( [Sales$ YoY%] ) < 1,
RIGHT ( " " & FORMAT ( [Sales$ YoY%], "0.0%" ), 6 ),
FORMAT ( [Sales$ YoY%], "0%" )
),
VALUES ( 'Parameter'[calculations] ) = "YoY Gap", RIGHT ( " $" & FORMAT ( [Sales$ YoY Gap], "0,0" ), 12 ),
VALUES ( 'Parameter'[calculations] ) = "Current Year Actuals", RIGHT ( " $" & FORMAT ( [Sales$ CY], "0,0" ), 12 ),
BLANK ()
),
BLANK ()- cuohanele6 years ago
Helper I
If there were negative percentages, how will the code look? Ran into that issue
- cuohanele6 years ago
Helper I
What if there are negative numbers? I tried applying the same logic of your previous DAX to other columns with negative percentages and negative dollar amounts. I ran into this:
- Anonymous6 years agoNot applicableHi
Didn't I say already that you'll be having a pretty hard time to get this to work correctly? And there'll probably always be cases not accounted for... If I were you, I'd stay away from such BRITTLE CODE.