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

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

Related

Sum of times value in one column appears in another column

I have a table of the customers check out funnel through an app and a table of total sales. I want to find the number of sales that can be attributed to the app. I think the easiest way to do this is to concatenate the name and barcode in both of these tables. Then I can see if the values column, NameVIN, for the sales table appear in NameVIN for the checkout funnel table.
For obvious reasons I will not be sharing data for this question.
NameVIN =
if(
ConsumerFunnelTime[CustomerFirstName] <> BLANK() && ConsumerFunnelTime[CustomerLastName] <> BLANK(), ConsumerFunnelTime[CustomerFirstName] & ConsumerFunnelTime[CustomerLastName] & ConsumerFunnelTime[VIN],BLANK())
NameVIN =
if(
'Sales'[c_Customer1FirstName] <> BLANK() && 'Sales'[c_Customer1LastName] <> BLANK(), 'Sales'[c_Customer1FirstName] || 'Sales'[c_Customer1LastName] & 'Sales'[v_VIN],BLANK())
This is what I tried to see of there is a matching value for NameVIN in both Sales and Consumer Funnel
VAR x = VALUES(ConsumerFunnelTime[NameVIN])
RETURN
CALCULATE(
COUNTROWS(ConsumerFunnelTime),
ALL(),
TREATAS( x, 'Sales'[NameVIN])
) + 0
I also tried this, but it is giving me an error for the syntax of CALCULATE.
DarwinSales =
VAR UsersNameVIN = ConsumerFunnelTime[NameVIN]
CALCULATE(
COUNT('Sales'[NameVIN]),
'Sales'[NameVIN] = UsersNameVIN
)
WasSale =
LOOKUPVALUE('Sales'[NameVIN], 'Sales'[NameVIN], ConsumerFunnelTime[NameVIN])
DarwinSales =
DISTINCTCOUNT(ConsumerFunnelTime[WasSale])

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 get string value in power bi with DAX

I want to get the text value from latest month but I don't know what's wrong with the DAX.
cm_comm =
VAR MaxKey = [MaxMonthKey]
RETURN
CALCULATE (
VALUES ( atm_commentary[Commentary] ),
atm_commentary[MonthRolNo] = MaxKey
)

Power BI: Calculating average of a column's current row divided by the first

Please see the file I have shared in the following link:
https://drive.google.com/file/d/1q7FE85qHoB_OhAm4hlmFidh6WP3m-UnK/view?usp=sharing
I have a dataset with the value of various items on different dates. I first need to calculate ratio by dividing the value of an item on a particular date with the earliest value in the chosen date filters. I then need to show the per day ratio of all items (columns I & J) as the desired output.
I am able to get the "first value" in the filtered table by using the following formula:
first_cr =
VAR item = MAX('Table 1'[item])
VAR min_updated = CALCULATE(
MIN('Table 1'[last_updated]),
'Table 1'[item] = item,
ALLSELECTED('Table 1')
)
RETURN
CALCULATE(
AVERAGE('Table 1'[cr]),
'Table 1'[last_updated] = min_updated,
'Table 1'[item] = item,
ALLSELECTED('Table 1'[fk])
)
However, I am unable to figure out how to calculate the average of all the individual item ratios at just the date level. I guess I need to use AVERAGEX somehow, but not sure how. Perhaps my first_cr formula could use more refinement.
I'd appreciate any help or guidance in the right direction. Thanks for your time.
I was able to get the answer using the following formula. If anyone can refine it better, please do so, else I'll accept my answer after a few days.
ret =
var lastUpdated = MAX(Sheet1[Date])
var tbl = ALLSELECTED(Sheet1)
RETURN
CALCULATE(
AVERAGEX(
Sheet1,
var i = Sheet1[Item]
var minUpdated = CALCULATE(
MIN(Sheet1[Date]),
Sheet1[Item] = i,
tbl
)
var first_cr = CALCULATE(
AVERAGE(Sheet1[Return]),
Sheet1[Date] = minUpdated,
Sheet1[Item] = i,
tbl
)
RETURN Sheet1[Return] / first_cr
),
Sheet1[Date] = lastUpdated,
tbl
)

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

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