Is there a way to add line breaks in a string of text in Microsoft's DAX language? - line-breaks

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!

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

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
",
"
)

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
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

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

The one that worked for me is <br/>.
Do something like this:
String = CONCATENATE(CONCATENATE("HEADER","<br/>"),"BODY")
The espected output is:
HEADER
BODY

Related

Keep current month selected in slicer in Power BI

I have a slicer having a list of MONTH-YEAR list like this:
Jul-22
Aug-22
Sep-22
Oct-22
...
...
From the above list i want current month to be selected.
I have tried with the code below:-
CurrMonth = if(month([Date])=Month(NOW()),month([Date]))
and got the current month but not able to set in the slicer.
any help please...
CurrMonth =
VAR _thismonthstart = DATE(YEAR(TODAY()),MONTH(TODAY()),1)
VAR _thismonthfinish = EOMONTH(_thismonthstart,0)
return
if [Date] >= _thismonthstart && [Date] <= _thismonthfinish then 1 else 0
alternatively, you can use the Filter on the visual
another alternative is to create a custom Special Dates Table which has a cross filter direction both ways with your date table.
Sample Solution
I have found the solution as below:
CurrMonth = if(month([Date])=Month(NOW()),CurMonth,FORMAT([Date], "MMM") & " " & [Year])
and set CurrMonth as the Field of the Slicer.
CurrMonth =
IF (
SELECTEDVALUE ( [Date] ) = FORMAT ( NOW (), "mmm-yy" ),
[Date],
FORMAT ( NOW (), "mmm-yy" )
)

PowerBi Circular Dependancy issue

I have a case where I'm getting a circular dependency.
I'm trying to calculate what stock will arrive to our warehouse by a certain date, but the eta_date is a calculated date column.
The formula reporting the problem is this :
SIT Arriving Soon =
VAR PastDate = Today() - 40
VAR FutureDate = TODAY() + 14
return
CALCULATE(SUMX(OnOrder,OnOrder[Open ASN qty [units]]]), DATESBETWEEN(OnOrder[ETA Date],PastDate, FutureDate)
)
The issue is that the datesbetween function needs a column to refer to, and my column is the calculated column below, which only refers to other columns within the 'onorder' table:
to understand this formula, here is a small key:
InT is a true/false if a quantity is in transit
Open ASN qty = the qty that is in transit
I then look at different vendors and the shipping mode used to add the number of days transport time.
I then do a calculation to add to the transport time to the 'invoiced by supplier' date, and if the vendor is not one of the defined vendors, then we use the default calculated date "OnOrder[Target VSL3 Date]"
ETA Date =
Var InT = if ( OnOrder[Open ASN qty [units]]] <> 0, 1,0)
Var AAVend = if( OnOrder[Vendor] = "451633" ||
OnOrder[Vendor] = "97051583"||
OnOrder[Vendor] = "452825", "AA", "Non-AA")
Var AATransTime = if( AAVend = "AA", IF(OnOrder[Ship Mode] = "Blitz", 5, IF(OnOrder[Ship Mode] = "Air", 14, 42)), 500)
var TransTime = IF(AATransTime > 0, AATransTime, 99999)
RETURN
if ( InT = 1, DATEADD(OnOrder[Ship Date].[Date], TransTime,DAY), OnOrder[Target VSL3 Date]. [Date])
Can anyone help me to get this issue sorted, or advise a way on how I could calculate this?
Thanks very much!
Ditch the DATESBETWEEN and just filter on the date column:
SIT Arriving Soon =
VAR PastDate = Today() - 40
VAR FutureDate = TODAY() + 14
return
CALCULATE(SUM(OnOrder[Open ASN qty [units]]]), OnOrder[ETA Date] >= PastDate && OnOrder[ETA Date] <=FutureDate)
)
thanks for the reply. I tried the formula, and I still get the circular reference error. It talks about the field 'ADC invoice number'. Here is the code to that :
ADC Invoice No =
CALCULATE ( FIRSTNONBLANK ( 'ADC Movements'[ADC Invoice Number], 1 ), FILTER ( ALL ( 'ADC Movements' ), 'ADC Movements'[PoFull] = OnOrder[PoFull] ) )
I don't see how this conflicts at all.

How to put a Hyphen in column Total Cost Value in power bi

I have a table with blank value, but i want a hyphen "-" to appear when the value is null.
Using an expression similar to this:
var VLGROUP =
(Expression……
RETURN
IF(
ISBLANK(VLGROUP),
BLANK(),
VLGROUP)
Someone know if is possible?
Thanks!!
enter image description here
gur.com/C0u8s.png
Try this below option-
Sales for the Group =
var sales =
CALCULATE(
SUM(Financialcostcenter[amount]),
Financialcostcenter[partnercompany]= "BRE",
Financialcostcenter[2 digits]=71,
DATESYTD('Datas'[Date])
)
+
CALCULATE(
SUM(Financialcostcenter[amount]),
Financialcostcenter[partnercompany]= "GRM",
Financialcostcenter[2 digits]=71,
DATESYTD('Datas'[Date])
)
RETURN IF(sales = BLANK(),"-", -(sales))

TopN, Grouping, Show Others at the bottom POWERBI-DAX

I have the following formula which creates the table in the screenshot below on the left (names of actual tables are different - also it combines 2 separate tables in one) -
Top 11 Jun =
IF (
[Type Rank Jun] <= 11,
[Total Jun],
IF (
HASONEVALUE ( Partners[partner_group] ),
IF (
VALUES ( Partners[partner_group] ) = "Others",
SUMX (
FILTER ( ALL ( Partners[partner_group] ), [Type Rank Jun] > 11 ),
[Total Jun]
)
)
)
)
Now i'm stuck on how to combine the "Null" and "Others" under "Others" and put "Others" at the bottom.i can combine the "Null" & "Others" at each table level, i'm just not sure how.
The DAX solution:
To get the Other and blank (at least that is how I read your null) together, you can create a new column on the table (is easiest).
newProducts = IF(fruits[product] = BLANK(); "Other";fruits[product])
A better solution is to replace your blanks (or NULL) in the Query language:
Go to: Edit Query:
Select your table and the product column and press on the bar the "Replace values"
Do the replace and save and close the editor.
Last step
It is not relevant in which order you have the rows in the table because you can control this in the visual self.
Below example:
As you can see, I filtered other out, this is not needed when you want to count them in your top N.
If you want to show all four, we need to make a new Table:
Tabel =
var Top3 = TOPN(3;FILTER(fruits;fruits[product] <> "Other") ;fruits[July Avail])
var prioTop3 = ADDCOLUMNS(Top3;"Order"; CALCULATE(COUNTROWS(fruits);FILTER(Top3; fruits[July Avail] <= EARLIER(fruits[July Avail]))))
var Other = ADDCOLUMNS(GROUPBY(FILTER(fruits;fruits[product] = "Other");fruits[product];"June Avail"; SUMX(CURRENTGROUP();fruits[June Avail]); "July Avail"; SUMX(CURRENTGROUP();fruits[July Avail]));"Order";0)
return UNION(prioTop3; Other)
Result:

PowerBI Getting ERROR A function 'CALCULATE' has been used

I would like to show the card values:
if current month value is not available then it should compare with the previous month value automatically.
Like
In above image Apr-2017 value is not available then it should compare with the Mar-2017 value.
If Mar-2017 value also not available then the previous month value.Keep on goes.
And one more thing is I don't want to use the slicer anymore. Actually I am not going to use the slicer.
I just want to show the month comparison value in a card visuals.
I would like to give info of what kind of data that I have. I have table's plan rev, actual rev, and MonthYear
I have created a relationship using Date column from MonthYear table to plan rev and actual rev Date columns.
MonthYear table
And in plan rev, month year, plan rev, date, and in actual rev actual rev, month year, and date columns.
Then written measures for
For Sumof Plan rev-->
PlanSum = SUM('Revenue Report'[Planned Rev])
For Prev month value-->
PlanPrevMon = CALCULATE([PlanSum],PREVIOUSMONTH('Month Year'[Date]))
For Start and End Date of the months
FILTERDATESTART= FIRSTDATE('MonthYear'[Date])
FILTERDATEEND= LASTDATE('MonthYear'[Date])
Then for current month PlanArrows measure is.
PlanArrows = CALCULATE(
IF(
ISBLANK([PlanSum]),"No data Available",[PlanSum]
)& " "& IF(
[PlanSum]=[PlanPrevMon],
"",
IF([PlanSum]>[PlanPrevMon],
UNICHAR(8679),
UNICHAR(8681)
) & IF([PlanSum]<=0,
"",""
)
),
'Month Year'[Date]>=FILTERDATESTART,
'Month Year'[Date]<=FILTERDATEEND
)
But it is not working. I'm getting an error:
A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expression. This is not allowed.
Any Suggestions please,
Thanks
Mohan V
I think i got the solution on my own.
I have written measure which solved this issue.
PlanArrows =
VAR s = [FILTERDATESTART]
VAR e = [FILTERDATEEND]
RETURN
CALCULATE (
IF ( ISBLANK ( [PlanSum] ), "No data Available", [PlanSum] ) & " "
& IF (
[PlanSum] = [PlanPrevMon],
"",
IF ( [PlanSum] > [PlanPrevMon], UNICHAR(8679), UNICHAR(8681) )
& IF ( [PlanSum] <= 0, "", "" )
),
'Month Year'[Date] >= s
&& 'Month Year'[Date] <= e
)