How to split list of strings into two columns and append it to a spire pdf in c# - list

This is my list of data type string:
List<string> Questions = new List<string>();
I am appending list of static questions ,answers to the question values from model
Questions .Add("Q1? " + " : " + model.value);
Questions .Add("Q2?" + " : " + model.value);
string[][] datasource = new String[Questions .Count][];
for (int i = 0; i < Questions .Count; i++)
{
datasource[i] = Questions [i].Split(';');
}
Appending it to spire pdf table:
PdfTable table = new PdfTable();
table.DataSource = datasource;
MY output:
What type of tax return does the entity file? : 604 --In single column
Expected output:
column1 column2
What type of tax return does the entity file? 604

Kindly note that there's only one set of data in every element of the array "Questions", thus the table only has a single column. If you want the expected output of two columns, please change your code as:
string[] Questions = { "Q1?:;model.value", "Q2?:;model.value" };

Related

power bi DAX hierarchical table concatenation of names

Since two days I'm on a problem and I can't solve it so I come here to ask some help...
I have that bit of dax that basically take the path of a hierarchical table (integers) and take the string names of the 2 first in the path.
the names I use:
'HIERARCHY' the hierarchical table with names, id, path, nbrItems, string
mytable / addedcolumn1/2 the new table used to emulate the for loop
DisplayPath =
var __Path =PATH(ParentChild[id], ParentChild[parent_id])
var __P1 = PATHITEM(__Path,1) var __P2 = PATHITEM(__Path,2)
var l1 = LOOKUPVALUE(ParentChild[Place],ParentChild[id],VALUE(__P1))
var l2a = LOOKUPVALUE(ParentChild[Place],ParentChild[id],VALUE(__P2))
var l2 = if(ISBLANK(l2a), "", " -> " & l2a)
return CONCATENATE(l1,l2)
My problem is... I don't know the number of indexes in my path, can go from 0 to I guess 15...
I've tried some things but can't figure out a solution.
First I added a new column called nbrItems which calculate the number of items in the list of the path.
The two columns:
Then I added that bit of code that emulates a for loop depending on the number of items in the path list, and I'd like in it to
get name of parameters
concatenate them in one string that I can return and get
string =
var n = 'HIERARCHY'[nbrItems]
var mytable = GENERATESERIES(1, n)
var addedcolumn1 = ADDCOLUMNS(mytable, "nom", /* missing part: get name */)
var addedcolumn2 = ADDCOLUMNS(addedcolumn1, "string", /* missing part: concatenate previous concatenated and new name */)
var mymax = MAXX(addedcolumn2, [Value])
RETURN MAXX(FILTER(addedcolumn2, [Value] = mymax), [string])
Full table:
Thanks for your help in advance!
Ok, so after some research and a lot of try and error... I've came up to a nice and simple solution:
The original problem was that I had a hierarchical table ,but with all data in the same table.
like so
What I did was, adding a new "parent" column with this dax:
parent =
var a = 'HIERARCHY'[id_parent]
var b = CALCULATE(MIN('HIERARCHY'[libelle]), FILTER(ALL('HIERARCHY'), 'HIERARCHY'[id_h] = a))
RETURN b
This gets the parent name from the id_parent (ref. screen).
then I could just use the path function, not on the id's but on the names... like so:
path = PATH('HIERARCHY'[libelle], 'HIERARCHY'[parent])
It made the problem easy because I didn't need to replace the id's by there names after this...
and finally to make it look nice, I used some substitution to remove the pipes:
formated_path = SUBSTITUTE('HIERARCHY'[path], "|", " -> ")
final result

Power BI, Power Query - Go trough list and add text with each step (for each)

I have a list for example:
A
B
C
D
Now I want to create a query in power query that will create a text like this:
"The letters are: " A B C D
I already have this query:
let
xx= KEYListfunction(),
list = Text.Split(xx, ","),
text = "",
loop = List.Accumulate(list, 0, (state, current) => text = text & " " & current ))
in
loop
But the result only says "FALSE"
Are you looking for this?
let
list = {"A".."D"},
text = "The letters are: " & Text.Combine(list, ", ")
in
text

Split row in multiple other rows in Power Bi based on a division of a number

In Power BI Desktop i have a table from an excel file and i want to split a row based on a division between the value of a specific column and a default number.
In more details lets assume tha we have a table like this :
if the default value we want to devide column Amount is 50,then the desirable result would be something like that :
Do you have any idea how can i implement that in Power query editor or with dax?
Thanks
Tested this in Power Query for Excel, but hopefully should work for you in Power BI too. If you create a function like:
divisionToList = (numberToDivide as number, numberToDivideBy as number) as list =>
let
divisionResult = numberToDivide / numberToDivideBy,
isResultValid = (divisionResult >= 0) and (Number.Mod(divisionResult, 1) = 0),
errorIfInvalid = Error.Record("Cannot create a list with " & Text.From(divisionResult) & " items", Number.ToText(numberToDivide) & " / " & Number.ToText(numberToDivideBy) & " = " & Text.From(divisionResult), null),
listOrError = if isResultValid then List.Repeat({divisionResult}, divisionResult) else error errorIfInvalid
in listOrError,
It should divide two numbers and return a list of length d in which each element is d (d is the result of the division). This list can then, in the context of a table, be expanded into new rows.
There is some basic error handling in the function for cases where the division yields a problematic number (since you can't have a list with, for example, 5.1 elements or -1 elements). You can change/remove this handling if necessary.
I think this code below takes me from your first image to your second image -- and hopefully will give you some idea on how to go about achieving this.
let
mockData = Table.FromColumns({{200, 400}, {"A", "B"}}, type table [Amount = number, Description = text]),
defaultValue = 50, // Not sure what logic is required for arriving at this figure, so have simply assigned it.
divisionToList = (numberToDivide as number, numberToDivideBy as number) as list =>
let
divisionResult = numberToDivide / numberToDivideBy,
isResultValid = (divisionResult >= 0) and (Number.Mod(divisionResult, 1) = 0),
errorIfInvalid = Error.Record("Cannot create a list with " & Text.From(divisionResult) & " items", Number.ToText(numberToDivide) & " / " & Number.ToText(numberToDivideBy) & " = " & Text.From(divisionResult), null),
listOrError = if isResultValid then List.Repeat({divisionResult}, divisionResult) else error errorIfInvalid
in listOrError,
invokeFunction = Table.TransformColumns(mockData, {{"Amount", each divisionToList(_, defaultValue), type list}}),
expanded = Table.ExpandListColumn(invokeFunction, "Amount")
in
expanded

Coldfusion dynamic column names to pass into a function

A user can supply answers for up to 5 question, and each question has 3 columns in the database:
st_m1_id
st_m1_fam
st_m1_cip
st_m2_id
st_m2_fam
st_m2_cip
etc
When the form is submitted I get the IDs into an array and then loop over that and then query a different table to look up fam and cip.
aidms = listToArray(form['idms[]']);
for( i=1;i<=arrayLen(aidms);i++ ) {
qryData = invoke(dataCFC,'queryData', { smid = aidms[i]});
temp = invoke(userCFC,'updateUser',{
userid = session.userid,
st_m#i#_id = aidms[i],
st_m#i#_fam = qryData.fam,
etc......
});
};
How do I notate the dynamic query column names in the function so that when they are passed to updateUser the correct columns are referenced?

Summing rows on a tabular form in apex 4.2 for validation

How can I sum fields on each row in a tabular form in APEX 4.2 to get a total for that row before I submit the page in order to do page validation?
For example if the first row has 6 in field a and 6 in field b the total for the first row should be 12 and on the second row if field b is 5 and field c is 5 the total for the second row should be 10.
So I want to get totals based on rows not column. Is that possible?
Yes, its possible. If you know javascript/jquery, you'll get along well with my solution. This is what you have to do:
get the name attribute(using inspect element of your browser) of the field you want to sum up. Names of fields in oracle apex usually goes like 'f01' or 'f02' and so on. Once you get the fields, create a javascript function or you can use this one if you like:
function sumUpRows(columnforsum,itemstobeadded){
var numofcols = arguments.length;
var numofrows = $("[name=" + arguments[0] + "]").length;
var summ = 0;
for(x=0;x<numofrows;x++){
for(i=1;i<numofcols;i++){
summ = summ + Number($("[name=" + arguments[i] + "]").eq(x).val());
}
$("[name=" + columnforsum + "]").eq(x).val(summ);
}
}
Put function above in "function and global variable declaration" part of your page. Then create a "before page submit" dynamic action. Set its action to "execute javascript" then put this line of code:
sumUpRows("nameoffieldwheresumwillbeassigned","nameofitem1","nameofitem2","nameofitem3");
Here's a sample :
sumUpRows("f04","f01","f02","f03");
For your question in the comment section, the answer is yes. To get the sum of a row automatically as you fill up the boxes on that row, you can use this function:
function sumUpRowsAsYouGo(whatelement){
var numofrows=$("[name=f01]").length;
var summ = 0;
for(i=0;i<numofrows;i++){
if($(whatelement).attr("id") == $("[name=" + $(whatelement).attr("name") + "]").eq(i).attr("id")){
for(a=1;a<(arguments.length-1);a++){
summ += Number($("[name="+ arguments[a] + "]").eq(i).val());
}
$("[name="+ arguments[arguments.length-1] + "]").eq(i).val(summ);
break;
}
}
}
you can use this function like this(put these lines in the "Execute on Page load" and "after refresh" dynamic action of your tabular form region):
$("[name=f01]").change(function(){
sumUpRowsAsYouGo(this,"f01","f02","f03","f04");
}
);
$("[name=f02]").change(function(){
sumUpRowsAsYouGo(this,"f01","f02","f03","f04");
}
);
$("[name=f03]").change(function(){
sumUpRowsAsYouGo(this,"f01","f02","f03","f04");
}
);