Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
I am trying to create a custom multiline KPIs using button/shape, below are my DAX codes, note I am not using card as left alignment is not possible in card. Any help would be highly appreciated.
Button/shape details:-
Button width = 350
Button height = 300
Monospace font used = Consolas
Horizontal Alignment of text = Left
Vertical Alignment of text = Top
DAX :-
Information Analytics1 =
VAR Space = " "
VAR CardWidth = 350
VAR Max_Text_Length = 45
VAR KPI1_Text = "Project Name :"
VAR KPI2_Text = "BOM :"
VAR KPI3_Text = "Region :"
VAR KPI4_Text = "NPV :"
VAR KPI5_Text = "IRR :"
VAR KPI1_Value = [ProjectName]
VAR KPI2_Value = [ProjectBOM]
VAR KPI3_Value = [ProjectRegion]
VAR KPI4_Value = [ProjectNPV]
VAR KPI5_Value = [ProjectIRR]
VAR KPI1_NumberOfSpaces_Left = Max_Text_Length - LEN(KPI1_Text)
VAR KPI2_NumberOfSpaces_Left = Max_Text_Length - LEN(KPI2_Text)
VAR KPI3_NumberOfSpaces_Left = Max_Text_Length - LEN(KPI3_Text)
VAR KPI4_NumberOfSpaces_Left = Max_Text_Length - LEN(KPI4_Text)
VAR KPI5_NumberOfSpaces_Left = Max_Text_Length - LEN(KPI5_Text)
VAR KPI1_NumberOfSpaces_Right = CardWidth - LEN(KPI1_Text)
VAR KPI2_NumberOfSpaces_Right = CardWidth - LEN(KPI2_Text)
VAR KPI3_NumberOfSpaces_Right = CardWidth - LEN(KPI3_Text)
VAR KPI4_NumberOfSpaces_Right = CardWidth - LEN(KPI4_Text)
VAR KPI5_NumberOfSpaces_Right = CardWidth - LEN(KPI5_Text)
VAR SummaryText =
KPI1_Text & REPT(Space,KPI1_NumberOfSpaces_Left) & KPI1_Value & REPT(Space,KPI1_NumberOfSpaces_Right) &
KPI2_Text & REPT(Space,KPI2_NumberOfSpaces_Left) & KPI2_Value & REPT(Space,KPI2_NumberOfSpaces_Right) &
KPI3_Text & REPT(Space,KPI3_NumberOfSpaces_Left) & KPI3_Value & REPT(Space,KPI3_NumberOfSpaces_Right) &
KPI4_Text & REPT(Space,KPI4_NumberOfSpaces_Left) & KPI4_Value & REPT(Space,KPI4_NumberOfSpaces_Right) &
KPI5_Text & REPT(Space,KPI5_NumberOfSpaces_Left) & KPI5_Value
RETURN
SummaryText
Output I got
Output I want
Thanks
Solved! Go to Solution.
HI @Saibal_78,
In fact, these are hard to manually modify space of the string to achieve specific layout and alignment. I'd like to suggest you only keep the padding part to keep these string show in the Center of card visual without other custom layouts: (these custom layout based on custom padding and repeating whitespace is simply broken when the card stretch or size reduced)
Information Analytics1 =
VAR Space = " "
VAR NeLine = UNICHAR ( 10 )
VAR KPI1_Text = "Project Name"
VAR KPI2_Text = "BOM"
VAR KPI3_Text = "Region"
VAR KPI4_Text = "NPV"
VAR KPI5_Text = "IRR"
VAR KPI1_Value = 1
VAR KPI2_Value = 2
VAR KPI3_Value = 3
VAR KPI4_Value = 4
VAR KPI5_Value = 5
VAR maxLength =
MAXX (
{
LEN ( KPI1_Text ),
LEN ( KPI2_Text ),
LEN ( KPI3_Text ),
LEN ( KPI4_Text ),
LEN ( KPI5_Text )
},
[Value]
)
VAR KPI1_Pading =
REPT ( Space, maxLength - LEN ( KPI1_Text ) )
VAR KPI2_Pading =
REPT ( Space, maxLength - LEN ( KPI2_Text ) )
VAR KPI3_Pading =
REPT ( Space, maxLength - LEN ( KPI3_Text ) )
VAR KPI4_Pading =
REPT ( Space, maxLength - LEN ( KPI4_Text ) )
VAR KPI5_Pading =
REPT ( Space, maxLength - LEN ( KPI5_Text ) )
VAR formatted=
KPI1_Text & KPI1_Pading & ":" & KPI1_Value & NeLine &
KPI2_Text & KPI2_Pading & ":" & KPI2_Value & NeLine &
KPI3_Text & KPI3_Pading & ":" & KPI3_Value & NeLine &
KPI4_Text & KPI4_Pading & ":" & KPI4_Value & NeLine &
KPI5_Text & KPI5_Pading & ":" & KPI5_Value & NeLine
RETURN
formatted
Regards,
Xiaoxin Sheng
HI @Saibal_78,
In fact, these are hard to manually modify space of the string to achieve specific layout and alignment. I'd like to suggest you only keep the padding part to keep these string show in the Center of card visual without other custom layouts: (these custom layout based on custom padding and repeating whitespace is simply broken when the card stretch or size reduced)
Information Analytics1 =
VAR Space = " "
VAR NeLine = UNICHAR ( 10 )
VAR KPI1_Text = "Project Name"
VAR KPI2_Text = "BOM"
VAR KPI3_Text = "Region"
VAR KPI4_Text = "NPV"
VAR KPI5_Text = "IRR"
VAR KPI1_Value = 1
VAR KPI2_Value = 2
VAR KPI3_Value = 3
VAR KPI4_Value = 4
VAR KPI5_Value = 5
VAR maxLength =
MAXX (
{
LEN ( KPI1_Text ),
LEN ( KPI2_Text ),
LEN ( KPI3_Text ),
LEN ( KPI4_Text ),
LEN ( KPI5_Text )
},
[Value]
)
VAR KPI1_Pading =
REPT ( Space, maxLength - LEN ( KPI1_Text ) )
VAR KPI2_Pading =
REPT ( Space, maxLength - LEN ( KPI2_Text ) )
VAR KPI3_Pading =
REPT ( Space, maxLength - LEN ( KPI3_Text ) )
VAR KPI4_Pading =
REPT ( Space, maxLength - LEN ( KPI4_Text ) )
VAR KPI5_Pading =
REPT ( Space, maxLength - LEN ( KPI5_Text ) )
VAR formatted=
KPI1_Text & KPI1_Pading & ":" & KPI1_Value & NeLine &
KPI2_Text & KPI2_Pading & ":" & KPI2_Value & NeLine &
KPI3_Text & KPI3_Pading & ":" & KPI3_Value & NeLine &
KPI4_Text & KPI4_Pading & ":" & KPI4_Value & NeLine &
KPI5_Text & KPI5_Pading & ":" & KPI5_Value & NeLine
RETURN
formatted
Regards,
Xiaoxin Sheng
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
11 | |
11 | |
10 | |
10 |
User | Count |
---|---|
19 | |
14 | |
13 | |
11 | |
8 |