I want to sum the elements of a table grouped by a field and then divided by a constant: For example, I have a table with department and sells and I want to sum all the sells of each department and then divide by 100 (for example). That's the code:
groupby(#NT(sells_factor = sum/100),sells_table,:department; select = :package)
Creating an anonymous function should work for you in one pass:
groupby(#NT(sells_factor = x -> sum(x)/100),sells_table, :department; select = :package)
I'd first calculate the sums and then divide them using map. See https://juliacomputing.github.io/JuliaDB.jl/latest/api/#Base.map-Tuple{Any,IndexedTables.AbstractIndexedTable}
Related
I have a riport, in which I need to make a measure, which counts the 'true' values of another measure.
My partner's sales prices are calculated with a measure, which is then put into a matrix visual.
Column 'A' contains the partner name (as there are several) Column 'B' is the item name, 'C' is their sales price and 'D' is the price they should sell the product for.
Example_1 matrix visual with open hierarchy:
What I need, is a measure, that I can put into the matrix, which then calculates those items, that are not sold for the given price, so when I close the table hieararchy and I only see the partner's name, I should have the info of how many products they sell for lower than given sales price (making it easier to rank them)
What I'm having trouble with, is to count the 'true' values of a measure, with another measure.
It's important, that I cannot make a new colmn into the source tables. I must have a measure, which counts 'True' values of another, as their sales prices are also calculated.
Example_2 matrix visual with closed hieararchy with the needed result value:
The first two items from Example_1 were sold for a lower than given price. My first measure will determine this by doing a true/false logical test.
My second measure which gives back two, should calculate the 'true' values of the first measure.
Practically the measures should look like this:
Measure_1 = if([measure_salesprice] < sum('given_pricelist'[Price] , "Lower" , "Not lower")
--> this one works perfectly
Measure_2 = Calculate(DISTINCTCOUNTX('Sales table', 'Sales table[Item name]),[measure_lowerpricetruorfalse] = "Lower")
--> now, this doesn't
Is this possible somehow?
I've tried several DAX combinatains like:
Calculate --> DISTINCTCOUNT, COUNTROWS, COUNTA, COUNTAX, COUNTX( with filter)
Always the same true/false error.
Please be informed that There is no function in DAX called DISTINCTCOUNTX ----> It is DISTINCTCOUNT only as of 2 Nov 2022:
Regarding your question: Use this DAX Code As Measure:
You don't need to categorize them as Lower or not Lower if you don't need this info to use later.
YourMeasure =
VAR GroupLower = FILTER(
'Sales table', [Partner sales price] < [Given sales price])
RETURN
COUNTX(
GroupLower,[Item name])
If you try to test it on a matrix visual:
I have a simple data set with training sessions for some athletes. Let's say I want to visualize how many training sessions are done as an average of the number of athletes, either in total or divided by the clubs that exist. I hope the data set is somewhat self-describing.
To norm the number of activities by the number of athletes I use two measures:
TotalSessions = COUNTA(Tab_Sessions[Session key])
AvgAthlete = AVERAGEX(VALUES(Tab_Sessions[Athlete]),[TotalSessions])
I give AvgAthlete as the desired value in both visuals shown below. If I make a filter on the clubs the values are as expected, but with no filter applied I get some strange values
What I guess happens is that since Athlete B doesn't do any strength, Athlete B is not included in the norming factor for strength. Is there a DAX function that can solve this?
If I didn't have the training sessions as a hierarchy (Type-Intensity), it would be pretty straightforward to do some kind of workaround with a calculated column, but it won't work with hierarchical categories. The expected results calculated in excel are shown below:
Data set as csv:
Session key;Club;Athlete;Type;Intensity
001;Fast runners;A;Cardio;High
002;Fast runners;A;Strength;Low
003;Fast runners;B;Cardio;Low
004;Fast runners;B;Cardio;High
005;Fast runners;B;Cardio;High
006;Brutal boxers;C;Cardio;High
007;Brutal boxers;C;Strength;High
If you specifically want to aggregate this across whatever choice you have made in your Club selection, then you simply write out a simple measure that does that:
AvgAthlete =
VAR _athletes =
CALCULATE (
DISTINCTCOUNT ( 'Table'[Athlete] ) ,
ALLEXCEPT ( 'Table' , 'Table'[Club] )
)
RETURN
DIVIDE (
[Sessions] ,
_athletes
)
Here we use a distinct count of values in the Athlete column, with all filters removed apart from on the Club column. This is, as far as I interpret your question, the denominator you are after.
Divide the total number of sessions on this number of athletes. Here is the result:
Sample representation of my dataset is below and I want to calculate the moving 7 day average of the total employees for a given set of dept, subgroup and team at a given date.
Is there some way I can pass this rowset to a C# method that can calculate the moving average? Is there another more efficient way to do this.
based on your data I did the following queries:
SELECT * FROM
(VALUES
(new DateTime(2019,01,01),"D1","S1","T1",20),
(new DateTime(2019,01,02),"D1","S1","T1",33),
(new DateTime(2019,01,03),"D1","S1","T1",78),
(new DateTime(2010,01,05),"D1","S2","T2",77)
) AS T(date,Dept, Subgroup, Team, Total_Employees);
#moving_Average_Last_7_Days =
SELECT DISTINCT
current.date,
current.Dept,
current.Subgroup,
current.Team,
current.Total_Employees,
AVG(lasts.Total_Employees) OVER(PARTITION BY lasts.Dept, lasts.Subgroup, lasts.Team,current.date) AS Moving_Average_Last_7_Days
FROM #moving_Average_Last_7_Days AS current
CROSS JOIN
#moving_Average_Last_7_Days AS lasts
WHERE (current.date - lasts.date).Days BETWEEN 0 AND 6
;
Please tell me if is this that you want to achieve!
i am using PHPExcel & searched a lot to get the result for setting the column width based on column number. I found results based on column id's but couldnt find any result for setting width based on column number. I am asking to know about, based on column number. What i tried before is
$length = strlen($tempval);
$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($dataColumn)->setWidth($length+10);
But it is hsowing me fatel error.. what supposed to be the right one??
You can get the Column ID from the Column Number using the
PHPExcel_Cell::stringFromColumnIndex(), pass the column index (e.g. 32 or 7) and it will return the column ID (like AG or H).
There is also a corresponding PHPExcel_Cell::columnIndexFromString() static method.... pass the column ID (like "AB") as an argument, and it will return the column number (e.g. 28).
Note that (for historic reasons) PHPExcel_Cell::stringFromColumnIndex() is 0-based (0 will return A, 1 will return B, etc); whereas PHPExcel_Cell::columnIndexFromString() is 1-based (A will return 1, B will return 2, etc).
In programmatically building cubes for SQL Server Analysis Services using AMO, I've discovered that when a measure has "Total" in it's title, the grand total in the cube is calculated by a distinct sum instead of just a sum (creating very strange results)
This doesn't occur when building cubes using DSO. Does anyone know of why this could be happening?
Please pardon my use of python:
class MeasureSpec(MeasureSpec):
def create(self, measureGroup, cube, dsv, factTable):
log("creating measure:", self.name)
measure = measureGroup.Measures.Add(self.name)
measure.AggregateFunction = self.aggregateFunction
measure.FormatString = self.format
# Set datatype to integer for counts otherwise this is set to the same
# type as the source column in createDataItem
if self.aggregateFunction in (aggCount, aggDistinctCount):
measure.DataType = MeasureDataType.Integer
measure.Visible = self.isVisible
measure.Source = createDataItem(dsv, factTable, self.column.getColumnName())
Here's what was going on. AMO was tagging the datacolumn as byte for anything with Total in the name. It was cycling to 32 which amazingly was the same number as a distinct sum on the column... Wow.