I want to create a calculated column. I have measures, and I want to visualize this calculated column using my already created measures.
I want my calculated column to look like below
All Groups --> (when I visualize the column with measures for this row, the measure value should show the sum of Group1 + Group2 + Group3)
I am using the expression below to create the calculated column, but it's not giving me the expected results.
NewColumn= var g1 = account no=3 var g2 = account no in { 4, 5, 6} && account group <> 20 var g3= account group = 20 return SWITCH(TRUE(),g1,"Group1",g2,"Group2",g3,"Group3", g1 || g2 || g3, "All Groups" )
Thanks in advance!
Related
I have table like this
i want to sum to get Total Team Score based on level and top 3 score based on score 1, score 2, score 3
TOTAL SCORE TEAM = Top3 Score 1 + Top3 Score 2 + Top3 Score 3
Result i hope
Can anyone help me how to get the result in my controller and my blade?
You should add Total score colum in your first colum then use this command to use this command to find whose score is highest level wise
$result=[];
for($k =0; $k<3 ;$k++)
$result[$k]=Cliente::max('total_score')->where('level',++$k)
I test this example it's successful
$data = DB::table('group_table')
->select('team','level',DB::raw('sum(score1 + score2 + score3) as total'))
->groupBy('team','level')
->get();
return response()->json($data);
DB
Result
I want to use Power Query to extract by field(field is [Project]), then get the top 3 scoring rows from the master table for each project, but if there are more than 3 rows with a score of over 15, they should all be included. 3 rows must be extracted every time as minimum.
Essentially I'm trying to combine Keep Rows function with my formula of "=if(score>=15,1,0)"
Setting the query to records with score greater than 15 doesn't work for projects where the highest scores are, for example, 1, 7 and 15. This would only return 1 row, but we need 3 as a minimum.
Setting it to the top 3 scores only would omit rows in a table where the highest scores are 18, 19, 20
Is there a way to combine the two function to say "Choose the top 3 rows, but choose the top n rows if there are n rows with score >= 15
As far as I understand you try to do following (Alexis Olson proposed very same):
let
Source = Excel.CurrentWorkbook(){[Name="Table"]}[Content],
group = Table.Group(Source, {"Project"}, {"temp", each Table.SelectRows(Table.AddIndexColumn(Table.Sort(_, {"Score", 1}), "i", 1, 1), each [i]<=3 or [Score]>=15)}),
expand = Table.ExpandTableColumn(group, "temp", {"Score"})
in
expand
Or:
let
Source = Excel.CurrentWorkbook(){[Name="Table"]}[Content],
group = Table.Group(Source, {"Project"}, {"temp", each [a = Table.Sort(_, {"Score", 1}), b = Table.FirstN(a, 3) & Table.SelectRows(Table.Skip(a,3), each [Score]>=15)][b]}),
expand = Table.ExpandTableColumn(group, "temp", {"Score"})
in
expand
Or:
let
Source = Excel.CurrentWorkbook(){[Name="Table"]}[Content],
group = Table.Group(Source, {"Project"}, {"Score", each [a = List.Sort([Score], 1), b = List.FirstN(a,3)&List.Select(List.Skip(a,3), each _ >=15)][b]}),
expand = Table.ExpandListColumn(group, "Score")
in
expand
Note, if there are more columns in the table you want to keep, for first and second variants you may just add these columns to last step. For last variant you haven't such option and the code should be modified.
Sort by the Score column in descending order and then add an Index column (go to Add Column > Index Column > From 1).
Then filter on the Index column choosing to keep values less than or equal to 3. This should produce a step with this M code:
= Table.SelectRows(#"Added Index", each [Index] <= 3)
Now you just need to make a small adjustment to also include any score 15 or greater:
= Table.SelectRows(#"Added Index", each [Index] <= 3 or [Score] >= 15)
How to convert Excel formula to Dax formula. I want to find out sum qty of previous day hour 24 if the current hour is 1 .
Below is the example using excel formula.
=IF(E3=1,SUMIFS($F$3:$F$17,$C$3:$C$17,D3,$E$3:$E$17,24),0)
date,previous date,hour,qty,Formula
10/10/2016,10/09/2016,24, 5,0
10/11/2016,10/10/2016, 1, 1,8
10/12/2016,10/11/2016,24, 2,0
10/13/2016,10/12/2016,24, 2,0
10/13/2016,10/12/2016, 3, 2,0
10/14/2016,10/13/2016, 1, 2,32
10/14/2016,10/13/2016, 1, 2,32
10/14/2016,10/13/2016,24,10,0
10/14/2016,10/13/2016, 4,10,0
10/14/2016,10/13/2016,24,10,0
10/13/2016,10/12/2016,24,10,0
10/13/2016,10/12/2016, 1,10,2
10/13/2016,10/12/2016,24,10,0
10/13/2016,10/12/2016,24,10,0
10/10/2016,10/09/2016,24, 3,0
Let's say your table is called Table1.
Create a calculated column with this formula:
CALCULATE(SUM(Table1[qty]),FILTER(Table1,[date] = (EARLIER([date]) - 1) &&
Table1[hour]=24 && EARLIER([hour]) = 1))
This will replicate the results you were able to calculate using SUMIFS() in Excel.
Now, you can totally use this formula and run with it, but the slight caveat is that it returns blank instead of 0 for cases where the formula does not apply. In order to handle that, you can use a blank check in DAX, like so:
=var x =
CALCULATE(SUM([qty]),FILTER(Table1,[date] = (EARLIER([date]) - 1) && Table1[hour]=24
&& EARLIER([hour]) = 1))
RETURN IF(ISBLANK(x),0,x)
Here's a screen of the results, with the calculated column on the right:
The above image represents generate statement below and describe too
D = FOREACH C GENERATE $0 AS time, $1 AS perf_temp_count;
DUMP D;
DESCRIBE D;
MY question is curretnly the above is grouped my Month and Hour(miltary time) and i am trying to find the max number next to it per each month. 1 through 12, right now i am just showing the month, hours, and numbers.
My expected out put is
(1, 4) 9
....
remaning months
....
(12, 3) 10
Where this again descibes ( Month, hour), Max count
B = GROUP A BY (month, hour);
C= FOREACH B GENERATE group as time,COUNT(A.temp) as cnt
X = GROUP C By time;
Y = FOREACH X GENERATE group, MAX(C.cnt) as mcount;
I have no idea why, but Agrregating(MAX) right after another aggregate(COUNT) is a problem or I am not refrencing the names correctly.
I am trying to group by my table with multiple columns and checking if the grouping count is equal to 2. I have the query working for this part
var query = from product in Products
group by new { product.Product, product.Location, product.Customer } into grp
where grp.Count() != 2
The Product has an another property Category, which could only have two values "High" & "Low".
How can I change this query to handle the check for Category in addition to the grouping count.
Product Location Customer Category
A X C1 High
A X C1 Low
A Y C1 High
A Y C1 Low
A Y C1 Low
B X C1 High
B X C1 Medium
In the example above, except for Product A at Location X and Customer C1, all other records are invalid. The Location Y has two Lows and Product B has a category Medium which is not part of the list: High & Low.
If you want to include only specific categories, use a where .. expression:
var query = from product in Products
where product.Category == "Low" || product.Category == "High"
group ...