I am new to power bi and stuck while comparing values. Below is the ask.
I need to compare the value in Depart Column with the value in Depart Type Column with below given rules
IF values mismatch i need to report it as yes and if not with no as depicted. any leads via DAX or M-query will be helpful.
Regards
Mahi
You can create a column that calculates the types correctly like this:
Type = SWITCH(TRUE(),
SEARCH("Red", Table1[Depart], 1, 0) > 0, "Red",
SEARCH("Green", Table1[Depart], 1, 0) > 0, "Green",
SEARCH("High", Table1[Depart], 1, 0) > 0, "StairwayIN",
SEARCH("Low", Table1[Depart], 1, 0) > 0, "StairwayOUT",
SEARCH("Virtual", Table1[Depart], 1, 0) > 0, "Virtual",
BLANK()
)
From there you just need to test if [Type] = [Depart Type].
Here are a couple of relevant references you may find useful:
DAX String Comparison
Explanation of SWITCH(TRUE(), ...)
Related
I have task-related data ordered by Priority with corresponding Story Points that I would like to group into sprints. I can calculate the Cumulative Points. However, I'm struggling to create a measure (or even a calculated column) to forecast in which sprint the task will occur given a known Velocity.
Assume 'Velocity' = 10
enter image description here
My goal is to determine the forecast sprint as seen in the table image. Basically, the sum of story points for a sprint cannot exceed the velocity. Unfortunately, simply dividing the Cumulative Points by the Velocity and rounding doesn't work. In this case, the 11th task would fall into sprint 3, but the total story points for the sprint would exceed the velocity.
I've reviewed Greg Deckler's For/While solution, but I couldn't get it to work for this problem. I'm fairly new to DAX, but I did try a variety of other options but couldn't find a solution.
I would do this using Power Query / M language.
let
Source = Table.FromColumns({
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
{2, 5, 1, 3, 1, 3, 1, 7, 2, 1, 1, 5, 3}
}, type table [Priority = Int32.Type, Story Point = Int32.Type]),
Velocity = 10,
AddedSprint = Table.FromRecords(
List.Accumulate(
Table.ToRecords(Table.Sort(Source, "Priority")),
[TotalSP = 0, CurrentSprint = 1, Value = {}],
(state as record, record as record) as record =>
let sp = record[Story Point],
nextState =
if state[TotalSP] + sp > Velocity then [
TotalSP = sp,
CurrentSprint = state[CurrentSprint] + 1,
Value = state[Value] & {record & [Sprint = CurrentSprint]}
]
else [
TotalSP = state[TotalSP] + sp,
CurrentSprint = state[CurrentSprint],
Value = state[Value] & {record & [Sprint = CurrentSprint]}
]
in nextState
)[Value]
)
in
AddedSprint
If you have a limited number of sprints for your forecast, you could go with the following solution:
(My table is called: Plan)
Create a column with the following DAX syntax:
S1 = IF(SUMX(FILTER(Plan, Plan[Priority] <= EARLIER(Plan[Priority])), Plan[Story Points]) > 10, 0, SUMX(FILTER(Plan, Plan[Priority] <= EARLIER(Plan[Priority])), Plan[Story Points]))
S1 will return the cumulated value for every entry that is in Sprint 1.
Create n calculated measures/column depending on the number of sprints you want to forecast. (This is the bad thing about this solution as it does not scale):
S2 = IF(SUMX(FILTER(Plan, Plan[S1] = 0 && Plan[Priority] <= EARLIER(Plan[Priority])), Plan[Story Points]) > 10, 0, SUMX(FILTER(Plan, Plan[S1] = 0 && Plan[Priority] <= EARLIER(Plan[Priority])), Plan[Story Points]))
S3 = IF(SUMX(FILTER(Plan, Plan[S2] = 0 && Plan[S1] = 0 && Plan[Priority] <= EARLIER(Plan[Priority])), Plan[Story Points]) > 10, 0, SUMX(FILTER(Plan, Plan[S1] = 0 && Plan[S2] = 0 && Plan[Priority] <= EARLIER(Plan[Priority])), Plan[Story Points]))
S4 = IF(SUMX(FILTER(Plan, Plan[S2] = 0 && Plan[S3] = 0 && Plan[S1] = 0 && Plan[Priority] <= EARLIER(Plan[Priority])), Plan[Story Points]) > 10, 0, SUMX(FILTER(Plan, Plan[S1] = 0 && Plan[S2] = 0 && Plan[S3] = 0 && Plan[Priority] <= EARLIER(Plan[Priority])), Plan[Story Points]))
Create a new measure that returns the string related to the S1-S4 calculated measures:
Sprint = IF(Plan[S1] > 0, 1, IF(Plan[S2] > 0, 2, IF(Plan[S3] > 0, 3, IF(Plan[S4] > 0, 4))))
Go ahead and hide the S1-S4 columns...
If you have a limited number of sprints to forecast, this might be the way to go...
Hope this helps!
You can solve your problem using the Floor Function.
In Dax, I created a calculated column as such:
Sprint.Forecast = FLOOR(SheetName[cumulative.points],10)/10+1
It can also be done in excel using the floor function. Assuming the Cumulative Points column is in C you could get your forecast column by takeing
=FLOOR(C2,10)/10+1
Sample sheet link: https://docs.google.com/spreadsheets/d/16huMKzeqbg3gho5klvRj91878H1ZARIs4F9RVRwE9M0
Tab: Week 45-48
I have this arrayformula set to pull $ amount data from another tab:
Cell F42:
=IFERROR(IF(value(F4) = value(Settings!$B$26),ArrayFormula(INDEX(FullReport!$A:$A,SMALL(IF("Labour Cost"=FullReport!$A:$A,ROW(FullReport!$A:$A)+1),1))),""),0)
It leaves a blank field if the value is empty. I have another formula set to read this data if the value is greater than $0.00
Cell D38:
=SUM(((IF(C42 > 0, C42,C41)) + (IF(D42 > 0, D42,D41)) + (IF(E42 > 0, E42,E41)) + (IF(F42 > 0, F42,F41)) + (IF(G42 > 0, G42,G41)) + (IF(H42 > 0, H42,H41)) + (IF(I42 > 0, I42,I41))))+B39
Unfortunately it seems the blank field "" being generated in cell F42 is causing cell D38 to register as a value greater than $0.00 and is throwing the expected results off.
Looking for a way around this, thanks for any assistance.
if you run =IF(F42 > 0, F42, F41) the output is blank cell so all the concerns about arrayformula should be discarded.
on the other hand, there is =IF(D42 > 0, D42, D41) which results in FALSE so in your SUM there are summed 4 values: B39 + C41 + D41 + E41 resulting in $5,571.08 (see the red table)
if you expect the sum to exclude D41 value your IF formula should be:
=IF((D42=0)+(D42=""), D42, D41)
the + sign acts as OR
or you can just use:
=ARRAYFORMULA(SUMPRODUCT(IF(C42:I42*1>0, C41:I41, C42:I42)))+B39
On Power BI, how would I convert any row that is "Processed" OR "New" in my Status column, to be represented by a 1 in the new column (using DAX)?
Thanks!
You should be able to use an IF() function in a new calculated column.
NewCol = IF(Table1[Status] = "Processed" || Table1[Status] = "New", 1, 0)
You can also use the IN syntax instead of having multiple conditionals.
NewCol = IF(Table1[Status] IN {"Processed", "New"}, 1, 0)
Situation: I have table Bob where each row has a bunch of columns, including a Result, SessionID1, SessionID2.
Goal: I want to GroupBy SessionID1 and SessionID2 and see if any Results in the group are 0; I expect multiple rows to have the same ID1 and ID2 values. I then want to divide the count of groups with 0 results / the count of all groups.
Questions: I think I want something like:
GROUPBY (
Bob,
SessionID1,
SessionID2,
"Has at least 1 success",
???)
But what aggregator can I use for ??? to get a boolean indicating if any result in the group equals 0?
Also, if I want a count of groups with successes, do I just wrap the GROUPBY in a COUNT?
Consider this sample table:
You can try the following DAX to create a new summary table:
Summary = GROUPBY(Bob, Bob[SessionID1], Bob[SessionID2],
"Number of rows", COUNTX(CURRENTGROUP(), Bob[Result]),
"Number of successes", SUMX(CURRENTGROUP(), IF(Bob[Result] = 0, 1, 0)))
Then you can add a calculated column for the success ratio:
Success ratio = Summary[Number of successes] / Summary[Number of rows]
Results:
EDIT:
If what you want to calculate is something like Any success, then SUMMARIZE may be a better option to use than GROUPBY due to their function nature.
Summary2 = SUMMARIZE(Bob, Bob[SessionID1], Bob[SessionID2],
"Any success", IF(COUNTROWS(FILTER(Bob, Bob[Result] = 0)) > 0, 1, 0),
"Number of rows", COUNTROWS(Bob))
Results:
I have a table like this.
|PARAMKEY | PARAMVALUE
----------+------------
KEY |[["PAR_A",2,"SCH_A"],["PAR_B",4,"SCH_B"],["PAR_C",3,"SCH_C"]]
I need to split the values into three columns and I use REGEXP_SUBSTR. Here is my code.
SELECT REGEXP_SUBSTR(paramvalue, '[^],["]+', 1,1 ) PARAMETER
,REGEXP_SUBSTR(paramvalue, '[^],[",]+', 1, 2) VERSION
,REGEXP_SUBSTR(paramvalue, '[^],["]+', 1, 3) SCHEMA
FROM tmp_param_table
where paramkey = 'KEY'
UNION ALL
SELECT REGEXP_SUBSTR(paramvalue, '[^],["]+', 1, 4 ) PARAMETER
,REGEXP_SUBSTR(paramvalue, '[^],[",]+', 1, 5) VERSION
,REGEXP_SUBSTR(paramvalue, '[^],["]+', 1, 6) SCHEMA
FROM tmp_param_table
where paramkey = 'KEY'
UNION ALL
SELECT REGEXP_SUBSTR(paramvalue, '[^],["]+', 1, 7 ) PARAMETER
,REGEXP_SUBSTR(paramvalue, '[^],[",]+', 1, 8) VERSION
,REGEXP_SUBSTR(paramvalue, '[^],["]+', 1, 9) SCHEMA
FROM tmp_param_table
where paramkey = 'KEY';
and this is the result that i need.
PARAMETER | VERSION | SCHEMA
---------+---------+-------
PAR_A |2 |SCH_A
PAR_B |4 |SCH_B
PAR_C |3 |SCH_C
But the value is too long and I hope there is another way to make it simplier by using loop or anything.
Thanks
Try something like this:
with tmp_param_table as
(
select 'KEY' as PARAMKEY , '[["PAR_A",2,"SCH_A"],["PAR_B",4,"SCH_B"],["PAR_C",3,"SCH_C"]],["PAR_D",4,"SCH_D"]]' as PARAMVALUE from dual
),
levels as (select level as lv from dual connect by level <= 156),
steps as (select lv-2 as step from levels where MOD(lv,3)=0)
select step, (SELECT REGEXP_SUBSTR(paramvalue, '[^],["]+',1, step ) PARAMETER FROM tmp_param_table where paramkey = 'KEY') parameter,
(SELECT REGEXP_SUBSTR(paramvalue, '[^],["]+',1, step+1 ) PARAMETER FROM tmp_param_table where paramkey = 'KEY') version,
(SELECT REGEXP_SUBSTR(paramvalue, '[^],["]+',1, step+2 ) PARAMETER FROM tmp_param_table where paramkey = 'KEY') schema
from steps
Here
levels - returns numbers form 1 till 156 (52*3) (or whatever you need)
steps - are the numbers 1, 4, 7 etc with step 3
Results:
1 PAR_A 2 SCH_A
4 PAR_B 4 SCH_B
7 PAR_C 3 SCH_C
10 PAR_D 4 SCH_D
13
etc..
I have tried using regular expression
and part paramvalue column value into common separated value
SELECT
REGEXP_SUBSTR(COL, '[^],["]+', 1, 1) PARAMETER,
REGEXP_SUBSTR(COL, '[^],[",]+', 1, 2) VERSION,
REGEXP_SUBSTR(COL, '[^],["]+', 1, 3) SCHEMA
FROM
(
SELECT paramkey,REGEXP_SUBSTR(to_char(paramvalue),'[^][^]+',1,level ) COL
from tmp_param_table
connect by regexp_substr(to_char(paramvalue),'[^][^]+',1, level) is not null
)
WHERE COL <>','
I hope this may help.