I have a question regarding a multiple-year comparison report in Power BI and DAX. The first five columns in the below table show the example data, the sixth column shows the two requirements, and the last column shows whether a plan _ID in the first column meets the requirement. I hope to count the number of plan_IDs which meet both requirements for a specific season (e. g. Spring 2018).
enter image description here
As you can see from the last column, Spring 2018 has 3 "yes" while Spring 2019 has 6. Therefore, for Spring 2019, the "Count of Plans for This Year" is 6 while the "Count of Plans for The Last Year" is 3, as shown in the table below. The table is what I want to have.
enter image description here
My question is how to count the plans that meet the two requirements for a specific season/season_number such as Spring 2019/190.
I have been struggling in this situation for a long time. Any ideas or suggestions will be greatly appreciated.
One of the best ways is to create comparative table (with an inactive relationship with the fact table), the user will have the possibility to choose any two time perdiods and the single visual will show the comparison :
Here are two good videos explaining this subject fully:
https://www.youtube.com/watch?v=TF0lPIYjJfs
https://www.youtube.com/watch?v=knXFVf2ipro
If my understanding (as commented) is correct, just add a Custom Column to your table as below in the Power Query Editor-
Changed Type in line 2 is basically the Previous Step Name. Adjust this accordigly.
= Table.AddColumn(
#"Changed Type",
"counter or not",
each
let
current_year = Date.Year(DateTime.LocalNow()),
year_difference = current_year - [year] + 1,
current_date = DateTime.Date(DateTime.LocalNow()),
date_to_check_with = Date.AddYears(current_date,-(year_difference)),
meet_req = if [plan_date] <= date_to_check_with then "Yes" else "No"
in meet_req
)
And here is the final output-
Now your the column with Yes/No value. To count Yes per year, come back to report and create this below Measure-
yearly_yes_count =
CALCULATE(
COUNT(your_table_name[counted or not]),
FILTER(
ALLEXCEPT(your_table_name,your_table_name[year]),
your_table_name[counted or not] = "Yes"
)
)
Here is last year count-
last_year_yes_count =
VAR current_row_year = MIN(your_table_name[year])
RETURN
CALCULATE(
COUNT(your_table_name[counted or not]),
FILTER(
ALL(your_table_name),
your_table_name[counted or not] = "Yes"
&& your_table_name[Year] = current_row_year - 1
)
)
Now add Year and new measure yearly_yes_count to a table visual and the output will be as below-
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:
The data is like this:
example - name of database
detail - the first column the contain sting with number in it (the number can be attached to $ etc. like 25m$ and also can be decimal like 1.2m$ or $1.2M)
lets say the datatable look like this:
example$detail<- c("The cole mine market worth every year 100M$ and the equipment they use worth 30$m per capita", "In 2017 the first enterpenur realized there is a potential of 500$M in cole mining", "The cole can make 23b$ per year ans help 1000000 familys living on it")
i want to add a column to the example data table - named: "number" that will extract the first number in the string in column "detail". BUT if this number is equal to one of the numbers in vector "year" (its not in the example database - its a seprate list i created) i want it to extract the second number of the string example$detail.
so i create another years list (separate from the database),
years<-c(2016:2030 )
im trying to create new column - number
what i did so far:
I managed to add variable that extract the first number of a string, by writing the following command:
example$number<-as.integer( sub("\\D*(\\d+).*", "\\1", example$detail) ) # EXTRACT ONLT INTEGERS
example$number1<-format(round(as.numeric(str_extract(example$detail, "\\d+\\.*\\d*")), 2), nsmall = 2) #EXTRACT THE NUMBERS AS DECIMALS WITH TWO DIGITS AFTER THE . (ITS ENOUGH FOR ME)
example$number1<-ifelse(example$number %in% years, TRUE, example$number1 ) #IF THE FIRST NUMBER EXTRACTED ARE IN THE YEARS VECTOR RETURN "TRUE"
and then i tried to write a code that extract the second number according to this if and its not working, just return me errors
i tried:
gsub("[^\d]*[\d]+[^\d]+([\d]+)", example$detail)
str_extract(example$detail, "\d+(?=[A-Z\s.]+$)",[[2]])
as.integer( sub("\\D*(\\d+).*", "\\1", example$detail) )
as.numeric(strsplit(example$detail, "\\D+")[1])
i didnt understand how i symbolized any number (integer\digits) or how i symbolized THE SECOND number in string.
thanks a lot!!
List item
Since no good example data is provided I'm just going to 'wing-it' here.
Imagine the dataframe df has the columns year (int) and details (char), then
df = mutate(clean_details = sub("[^0-9.-]", "",details),
clean_details_part1 = as.integer(strsplit(clean_details,"[.]")[[1]][1]),
clean_details_part2 = as.integer(strsplit(clean_details,"[.]")[[1]][2])
)
This works with the code I wrote up. I didn't apply the logic because I see you're proficient enough to do that. I believe a simple ifelse statement would do to create a boolean and then you can filter on that boolean, or a most direct way.
I'm having some trouble figuring out how to put some data on a visualization.
I want a bar chart that has a list of computer labs on the x axis, and the "count of days where the sum of Util4 for that date is above 0.5 on the y axis
Some of the formulas for measures i've tried are:
High Util = COUNTAX('Login Sessions', SUM('Login Sessions'[Util4]) >0.5) doesn't work
High Util2 = COUNTROWS(FILTER('Login Sessions', 'Login Sessions'[Util4] >0.5)) only counts lines where Util4 is above 0.5, doesn't sum to find dates where multiple rows for this date add up to above 0.5
I'm missing some math know how here, I know i need to incorporate StartDate into my measure somehow, but not sure how. Any advice would be appreciated.
edit: In my dataset i have unique 289 dates. Each row is a login session that happened on a computer in a computer lab. I want to sum all of the Util4 numbers for that specific date\computer lab combination and then count how many times each computer lab had that sum be above 0.5. I do not know the proper way to do this.
My expectation would be numbers between 0 and 289 for each computer lab, which i could then make a visualization to show which rooms had util4 above 0.5 (50%) the most often.
Following will get you the sum of Util4 for each day/lab, add it as calculated column in your table:
Total Util =
VAR _Date = SELECTEDVALUE('Login Sessions'[StartDate])
VAR _Lab = SELECTEDVALUE('Login Sessions'[Ad Computers.Computer Lab])
RETURN
CALCULATE(
SUM('Login Sessions'[Util4]),
FILTER(
ALL('Login Sessions'),
'Login Sessions'[StartDate] = _Date &&
'Login Sessions'[Ad Computers.Computer Lab] = _Lab
)
)
Then create the following measure for the count:
_daysCount =
CALCULATE(
DISTINCTCOUNT('Login Sessions'[StartDate]),
FILTER(
ALL('Login Sessions'),
'Login Sessions'[Total Util] >0.5
)
)
Good day; I am looking for help creating a running total or a formula where I can see a count of a specific field that equals "No".
Currently I have a total count of {ems_SceneCall.CrewDecison} for all decisions, and now I want to add a count of {ems_SceneCall.CrewDecison} = "No". I have had success with this up to the point where I want to count to reset with each group.
Currently I have a Running Total Set to count the field, Evaluate records where {ems_SceneCall.CrewDecison} = "No", and reset on change of group. This running total only shows 1 or 0.
Another way to do this is a formula that says
if {ems_SceneCall.CrewDecison} = "No" then 1 else 0
Then create a group summary (SUM) to the group footers
I'm making a report in Cognos Report Studio and I'm having abit of trouble getting a count taht I need. What I need to do is count the number of IDs for a department. But I need to split the count between initiated and completed. If an ID occures more than once, it is to be counted as completed. The others, of course, will be initiated. So I'm trying to count the number of ID occurences for a distinct ID. Here is the query I've made in SQl Developer:
SELECT
COUNT((CASE WHEN COUNT(S.RFP_ID) > 8 THEN MAX(CT.GCT_STATUS_HISTORY_CLOSE_DT) END)) AS "Sales Admin Completed"
,COUNT((CASE WHEN COUNT(S.RFP_ID) = 8 THEN MIN(CT.GCT_STATUS_HISTORY_OPEN_DT) END)) as "Sales Admin Initiated"
FROM
ADM.B_RFP_WC_COVERAGE_DIM S
JOIN ADM.B_GROUP_CHANGE_REQUEST_DIM CR
ON S. RFP_ID = CR.GCR_RFP_ID
JOIN ADM.GROUP_CHANGE_TASK_FACT CT
ON CR.GROUP_CHANGE_REQUEST_KEY = CT.GROUP_CHANGE_REQUEST_KEY
JOIN ADM.B_DEPARTMENT_DIM D
ON D.DEPARTMENT_KEY = CT.DEPARTMENT_RESP_KEY
WHERE CR.GCR_CHANGE_TYPE_ID = '20'
AND S.RFP_LOB_IND = 'WC'
AND S.RFP_AUDIT_IND = 'N'
AND CR.GCR_RECEIVED_DT BETWEEN '01-JAN-13' AND '31-DEC-13'
AND D.DEPARTMENT_DESC = 'Sales'
AND CT.GCT_STATUS_IND = 'C'
GROUP BY S.RFP_ID ;
Now this works. But I'm not sure how to translate taht into Cognos. I tried doing a CASE taht looked liek this(this code is using basic names such as dept instead of D.DEPARTMENT_DESC):
CASE WHEN dept = 'Sales' AND count(ID for {DISTINCT ID}) > 1 THEN count(distinct ID)END)
I'm using count(distinct ID) instead of count(maximum(close_date)). But the results would be the same anyway. The "AND" is where I think its being lost. It obviously isn't the proper way to count occurences. But I'm hoping I'm close. Is there a way to do this with a CASE? Or at all?
--EDIT--
To make my question more clear, here is an example:
Say I have this data in my table
ID
---
1
2
3
4
2
5
5
6
2
My desired count output would be:
Initiated Completed
--------- ---------
4 2
This is because two of the distinct IDs (2 and 5) occure more than once. So they are counted as Completed. The ones that occure only once are counted as Initiated. I am able to do this in SQl Dev, but I can't figure out how to do this in Cognos Report Studio. I hope this helps to better explaine my issue.
Oh, I didn't quite got it originally, amending the answer.
But it's still easiest to do with 2 queries in Report Studio. Key moment is that you can use a query as a source for another query, guaranteeing proper group by's and calculations.
So if you have ID list in the table in Report Studio you create:
Query 1 with dataitems:
ID,
count(*) or count (1) as count_occurences
status (initiated or completed) with a formula: if (count_occurences > 1) then ('completed') else ('initiated').
After that you create a query 2 using query one as source with just 2 data items:
[Query1].[Status]
Count with formula: count([Query1].[ID])
That will give you the result you're after.
Here's a link to doco on how to nest queries:
http://pic.dhe.ibm.com/infocenter/cx/v10r1m0/topic/com.ibm.swg.ba.cognos.ug_cr_rptstd.10.1.0.doc/c_cr_rptstd_wrkdat_working_with_queries_rel.html?path=3_3_10_6#cr_rptstd_wrkdat_working_with_queries_rel