9

I have a DAX function that pulls in multiple strings of text (from multiple columns) into one cell. But on display I want to have a line break in between the header and the body of the paragraph. Is there a way to code in a line break with DAX? FYI, I'm using Power BI for this. Thanks!

jschlereth
  • 1,071
  • 2
  • 10
  • 12
  • 2
    The usual "suspects" \n\r and
    just gave me "\n\r and
    " respectively in the text field....
    – jschlereth Mar 10 '16 at 15:43
  • Can you use power Query to importa data? if you can do this i have used a solution time ago to insert carriage return between string. let me know – nicolò grando Mar 11 '16 at 11:50
  • 1
    You can use power query to import data, but I'm looking to create a new carriage return and don't know the code to do so... – jschlereth Mar 16 '16 at 14:58

5 Answers5

12

Using DAX String = [field A] & UNICHAR(10) & [field B]

Example: Field A contains text: January 11, 2018 Field B contains text: Happy Birthday Elvis

This will return:

January 11, 2018

Happy Birthday Elvis

Beth Hall
  • 121
  • 1
  • 2
10

In BI Desktop, just type alt-enter in your DAX formula to add new line For example:

CONCATENATEX(Project, ProjectName & ":" & [some-measure], 
//new line in parameter delimiter
",
"
)
nguyen giang
  • 109
  • 1
  • 3
  • This is a good solution for this, but using Variables is recommended in the DAX Formula as it can be used multiple time. Find an example here: https://community.powerbi.com/t5/Desktop/how-to-get-text-in-new-line-in-the-data-cards-label/m-p/441556/highlight/true#M203915 – Gangula Jul 14 '19 at 18:32
2

First, we have to create string concatenation using CONCATENATE() method, then use UNICHAR(10) to create space between strings

Product Sold Count =

VAR Valuel = "Product Sold" 

VAR Value2 = "Today : " & (
                            CALCULATE(
                                SUMX(
                                    FILTER(
                                            'api_Product Sold',
                                            'api_Product Sold'[Date] = TODAY()
                                        ),
                                    'api_Product Sold'[Count]
                                    )
                                )
                        + 0 ) 

VAR Value3 = "Total : " & (
                            CALCULATE(
                                SUMX(
                                    FILTER(
                                            'api_Product Sold',
                                            'api_Product Sold'[Date] <= TODAY()
                                        ),
                                    'api_Product Sold'[Count]
                                    )
                                )
                        + 0 )  

VAR FirstCONCATENATE = CONCATENATE(CONCATENATE(Valuel,UNICHAR(10)),Value2) 

VAR SecondCONCATENATE = CONCATENATE(CONCATENATE(Value2,UNICHAR(10)),Value3) 

RETURN SecondCONCATENATE

Once your string is ready then select card chat and assign the measure created

enter image description here

Where height of the card chart should be proper then only word wrap will work and before it should be enable the word wrap property on format tab

enter image description here

KARTHIKEYAN.A
  • 18,210
  • 6
  • 124
  • 133
-1

The PowerqueryFormulaReference uses in the Lines.ToText example something like #(cr)#(lf) I added this as a string (!) to my text and it worked...

Christian
  • 7
  • 1
  • 2
    I hate to split hairs (especially in a discussion about concatenation:-) ) but PowerQuery is not DAX. The question seems to be specifically about DAX. – DatumPoint Jun 07 '18 at 01:23
-4

The one that worked for me is <br/>.

Do something like this:

String = CONCATENATE(CONCATENATE("HEADER","<br/>"),"BODY")

The espected output is:

HEADER
BODY

V Maharajh
  • 9,013
  • 5
  • 30
  • 31
S. Mendez
  • 33
  • 6