Format an amount to a specific display - dax

I have a measure in Tabular that calculates an amount I want the display to be like below :
1 990K
I tried to use FORMAT but in vain.
MyMeasure :=FORMAT ( SUM(MyTable[Salary]), "#, 0.,,.0#K" )& "€"

Try the following in the Properties :
#,##0, K€

Related

How to format thousands from digit a with a point

I'am looking for the best way to format thousands from digit a with a point. I am creating a view from an other table and I need for some columns to have this type of format.
ex : 10000 -> 10.000
Thank you in advance for your possible answers !
There is way how to do it without UDF but it can be performance issue. But for small sets of data it works:
You can use the following combination of build-in functions:
// Template
select reverse(concat_ws(".",split(reverse(<column-to-format>),"(?<=\\G.{3})")));
// sample 1 - format number 12345678
select reverse(concat_ws(".",split(reverse("12345678"),"(?<=\\G.{3})")));
// sample 2 - format number 10000
select reverse(concat_ws(".",split(reverse("10000"),"(?<=\\G.{3})")));
Explanation for sample 1 with number 12345678
1. reverse("12345678") Result: 87654321
2. split(reverse("12345678"),"(?<=\\G.{3})")")) Result: array [876,543,21]
3. concat_ws(".",split(reverse("10000"),"(?<=\\G.{3})")) Result "876.543.21"
4. finally reverse it back. Result: "12.543.876"

How to compare two dates with current date in Tibco BW?

For Example, if you have a date coming from Start activity, How can we compare that date with current date?
There actually a function present exactly for that purpose. It is called compare-date or compare-dateTime (if time is also relevant).
The signature of this function is:
compare-date('1980-08-05','1980-09-04')
returns -1 if first
returns 1 if second
return 0 if both are equal.
In your case this could mean something like:
compare-date($Start/root/Date,current-date())
You can do in following way:
Take two mappers for example, for first use two inputs and give following xpath in an order:
1.For current Date :
tib:parse-date("yyyyMMdd",tib:format-date("yyyyMMdd",current-date()))
For Start Input
tib:parse-date("yyyy-MM-dd", $Start/root/Date)
and compare it in somewhere in your End's Input like:
if ($parseDate/root/currentdate= $parseDate/root/rDate) then substring(
$parseDate/root/currentdate - $parseDate/root/Date, 3,
string-length(($parseDate/root/currentdate - $parseDate/root/Date))-3) else
substring( $parseDate/root/currentdate - $parseDate/root/Date,2,
string-length(($parseDate/root/currentdate - $parseDate/root/Date))-2)

How to give equations in Apache pig

I am trying to get a value from this equation
--counted gives the total row count in a file
samplecount = counted*(10/100);
How to sample data according to this
--Load data
examples = LOAD '/home/sreeveni/myfiles/PE/USCensus1990New.csv' ;
--Group data
groupedByUser = group examples all;
--count no of lines in the file
counted = FOREACH groupedByUser generate COUNT(examples) ;
--sampling
sampled = SAMPLE examples counted*(10/100);
store sampled into '/home/sreeveni/myfiles/OUT/samplesout';
Showing error in above line
Invalid scalar projection: counted : A column needs to be projected
from a relation for it to be used as a scalar
Please advice.
Am I doing anything wrong.
i guess sample works with a number between [0,1]. In your case, its exceeding the required value. If you want just 10% of the data, pass 0.1 directly and to get that in a code, find this percentage in a FOREACH statement only.
If you are trying to generate a sample of "examples" with 10% of the total number of rows, all you have to do is:
SAMPLE examples 0.1;
Read the documentation for SAMPLE command here.

How to create missing records within date-time range in pig latin

I have input records of the form
2013-07-09T19:17Z,f1,f2
2013-07-09T03:17Z,f1,f2
2013-07-09T21:17Z,f1,f2
2013-07-09T16:17Z,f1,f2
2013-07-09T16:14Z,f1,f2
2013-07-09T16:16Z,f1,f2
2013-07-09T01:17Z,f1,f2
2013-07-09T16:18Z,f1,f2
These represent timestamps and events. I have written these by hand, but actual data should be sorted based on time.
I would like to generate a set of records which would be input to graph plotting function which needs continuous time series. I would like to fill in missing values, i.e. if there are entries for "2013-07-09T19:17Z" and "2013-07-09T19:19Z", I would like to generate entry for "2013-07-09T19:18Z" with predefined value.
My thoughts on doing this:
Use MIN and MAX to find the start and end date in the series
Write UDF which takes min and max and returns relation with missing
timestamps
Join above 2 relations
I cannot get my head around on how to implement this in PIG though. Would appreciate any help.
Thanks!
Generate another file using a script (outside pig)with all time stamps between MIN and MAX , including MIN and MAX. Load this as a second data set. Here is a sample that I used from your data set. Please note I filled in only few gaps not all.
2013-07-09T01:17Z,d1,d2
2013-07-09T01:18Z,d1,d2
2013-07-09T03:17Z,d1,d2
2013-07-09T16:14Z,d1,d2
2013-07-09T16:15Z,d1,d2
2013-07-09T16:16Z,d1,d2
2013-07-09T16:17Z,d1,d2
2013-07-09T16:18Z,d1,d2
2013-07-09T19:17Z,d1,d2
2013-07-09T21:17Z,d1,d2
Do a COGROUP on the original dataset and the generated dataset above. Use a nested FOREACH GENERATE to write output dataset. If first dataset is empty, use the values from second set to generate output dataset else the first dataset. Here is the piece of code I used on these two datasets.
Org_Set = LOAD 'pigMissingData/timeSeries' USING PigStorage(',') AS (timeStamp, fl1, fl2);
Default_set = LOAD 'pigMissingData/timeSeriesFull' USING PigStorage(',') AS (timeStamp, fl1, fl2);
coGrouped = COGROUP Org_Set BY timeStamp, Default_set BY timeStamp;
Filled_Data_set = FOREACH coGrouped {
x = COUNT(times);
y = (x == 0? (Default_set.fl1, Default_set.fl2): (Org_Set.fl1, Org_Set.fl2));
GENERATE FLATTEN(group), FLATTEN(y.$0), FLATTEN(y.$1);
};
if you need further clarification or help let me know
In addition to #Rags answer, you could use the STREAM x THROUGH command and a simple awk script (similar to this one) to generate the date range once you have the min and max dates. Something similar to (untested! - you might need to single line the awk script with semi-colon command delimitation, or better to ship it as a script file)
grunt> describe bounds;
(min:chararray, max:chararray)
grunt> dump bounds;
(2013/01/01,2013/01/04)
grunt> fullDateBounds = STREAM bounds THROUGH `gawk '{
split($1,s,"/")
split($2,e,"/")
st=mktime(s[1] " " s[2] " " s[3] " 0 0 0")
et=mktime(e[1] " " e[2] " " e[3] " 0 0 0")
for (i=st;i<=et;i+=60*24) print strftime("%Y/%m/%d",i)
}'`;

Math.Round() not working when exporting to excel

In my view which I am exporting to excel, I display the value of this variable
VeryGoodPercentage = subQst.Question.ReponseList.Where(
r => r.ReponseValeur == 4 &&
Model.SelectedGroupContactList.Select(c => c.ContaId).Contains(r.ContaId.Value)
).ToList().Count() * 100
/
denominator;
And I display this way
<td class=xl76 align=right width=69 style='width:52pt'>#Math.Round(VeryGoodPercentage)%</td>
When I display the view without exporting to excel, everything works just fine. But when I open the exported Excel file, I found the value of that variable not rounded.
For examlpe :
In the view : 36%
In the excel file : 0.36
I use this line to generate the file:
Response.AddHeader("Content-Type", "application/vnd.ms-excel");
As stated:
36% and 0.36 should be the same - just excel did not fomat this as a percentage or did indeed interpreted 36 as a percentage - which will result in 0.36 as a number.
I don't see that this is a rounding problem, it is formatting or input or both.
Depending on what values #Math.Round(VeryGoodPercentage) produce - 0.xx or XX.XX - with % sign or without, excel will interpret this differently.
Some examples:
=0.36 will result in a number of 0.36
=36 will result in a number of 36
no suprises so far, but now:
=0.36% will result to 0.0036
=36% will result to 0.36
BUT those were Formulars, now if you would just use F2 on an empty 'default' formatted cell and write into it:
36% -> you would format this as percentage, which would display this as 36%, but if you would format it as 'default', then it would be the number 0.36!
0.36% -> would behave like 36%
hope this clears more than it confuses ;) good luck to you!
edit: and to make this even more fuzzy, in my country . is the symbol for thounsands, so you would have to use , instead.
edit: with VBA you could setup your column or cell to use a specific numberformat like this:
Table1.Columns("A").NumberFormat = "0.00%"
I finally found the solution here
Format HTML table cell so that Excel formats as text?
just add this css param to the tag :
mso-number-format:Percent;

Resources