For a table with around 100 columns, how can I quickly calculate the sum of all columns for each row in DolphinDB? Looks like all DolphinDB functions for a table apply to columns, not rows.
DolphinDB's aggregate functions indeed apply to columns. Unfortunately, you'll have to write out this summation yourself (or write some code that generates it):
SELECT col1 + col2 + col3 + /* etc... */ AS sum_of_cols
FROM mytable
DolphinDB provides a built-in function named rowSum that exactly does what you want.
t = table(...)
rowSum(t)
You can find the official documentation here.
Related
I'm trying to concatenate 3 different tables in powerBI, with powerQuery but I couldn't find the solution for it. The closest I could find is appending the query, however it does not concatenate the table shown below.
Example:
Im trying to concatenate table Code1 to Code2 to Code3 (bottom 3 tables) to look like the top one.
Thank you very much for your help
Alternate method
In Table3, add column, custom column,
= Table1
then expand
Add column, custom column
= Table2
then expand
Add a custom column to each of your queries, all with the same value. For my test I just used the value of 1.
Then merge Query 1 to Query 2 on your custom column. Next, merge that query to Query 3 again on the custom column. Once you rearrange the columns you will get an output that looks like this:
I have a table C with a LOOKUPVALUE column from table A and another LOOKUPVALUE column from table B.
I would like to add another column, which is the sum of the two columns.
When I try to use a DAX Sum formula, I get error: The SUM function only accepts a column reference as an argument.
I tried to demonstrate visually what I am trying to do here :Visual of my problem
Instead of your measure/column-
TOTAL = SUM(TOGETHER(BATMAN) + TOGETHER(ROBIN))
Can you please try with -
TOTAL = TOGETHER(BATMAN) + TOGETHER(ROBIN)
Note: Guess BATMAN and ROBIN both are custom columns in your table
I'm having some issue regarding the filtering in Power BI/DAX. I have an example below. What I'm trying to achieve is to write a measure to filter out the rows where column 1 is "A" and Column 2 is "aa" and then sum the total of the rest of rows.
Thanks in advance!
You can use CALCULATE like this:
Sum of Filtered Values =
CALCULATE(
SUM('DataTable'[Amount]);
'DataTable'[Column1] = "A";
'DataTable'[Column2] = "aa"
)
The two rows below SUM() are filter arguments in the CALCULATE function. Each of the arguments removes all other filtering on their respective columns and then CALCULATE generates a table where the two filter arguments are combine with a logic AND, hence CALCULATE will SUM all [Amounts] where [Column1] is "A" and [Column2] = "aa".
This is basic DAX workflow. Read about CALCULATE, understand how the filter functions work (and their inherrent pitfalls), and learn to love it.
Trying to sort a column in my custom date table (a csv file) via a calculated column in the same table but am seeing an error. The calculated column does not reference the column I wish to sort by. Here's the DAX for the calculated column:
PeriodOffset =
Dates[Period] + Dates[FiscalYear] * 13
- CALCULATE ( VALUES ( Dates[Period] ), Dates[Date] = TODAY () )
- CALCULATE ( VALUES ( Dates[FiscalYear] ), Dates[Date] = TODAY () ) * 13
My date table has every date from 2003/4 to 2034/35, along with custom period numbers, calendar and fiscal years etc. The column I am trying to sort is called PeriodFiscalYear. Each value in that column has only one entry in the PeriodOffset column so it's not that.
The weird thing is, I have had this working in a previous report. In this instance, I was simply trying to recreate the functionality but it won't do it. Even stranger, if I create the PeriodFiscalYear column as a calculated column (currently it's hard-coded in the csv file), it works! So I have a sort-of workaround, I would just like to understand what is going on.
Thanks
I believe this has to do with the fact that data column are sorted when data are ingested into PBI. Calculated columns are calculated only at a later time.
Therefore:
you can sort data column only with other data columns (because calculated columns have not been calculated yet)
you can sort calculated column with both data column and calculated column
Solution:
A) PeriodFiscalYear becomes a calculated column
B) PeriodOffset becomes a data column (either in your CSV or Power Query)
I actually figured this out. The problem was with my data model - I had a circular relationship in there as I was deriving the Period column in one table using my calendar table then linking them back in the relationship!
I created a linking table with the keys in both to make the relationship, then hid it.
Thanks
I have a table that has (simplified) the columns CustID, Action, Date
I then have a matrix visual that has Action as Columns, CustID AS Rows and Count(Action) as Values.
Now I need an extra column that sums only some of the Columns, not all like the Total. In Excel this is =SUMME(B11:K11), where K12 and K13 are the columns not to be summed.
Is this possible in PBI Matrix?
You can simply create a measure.
(new_measure_name) = 'table'[field to add] + 'table'[field to add]
After you create the measure you can add it to the matrix and double check you math that it adds up like you want.
Good luck!
my problem was, that I had a table column in the column section of the matrx visual. than, when I add a measure it is only available in drill, not as extra column. I solved it with pivoting that column and use the new columns in data section. than I can add measures to the data section and they get also new columns.
would be nice, if I could use the column section and add measures