Cognos HTML Output Generates multiple rows for each column - list

I have report that has 6 Query Calculation Columns in a List. Each column feeds from the same field 'Sale Number':
IF( 'Metric 1' IN ?pCompany?)
THEN
(
CASE
WHEN ( [Metric] = 'Metric 1' ) THEN
( count( distinct [Sale Number] FOR [Metric], [Category] ))
END
)
ELSE
( 0 )
Each of these columns have the Detail and Summary Aggregation set to None. Calculation is working fine. However, the report is generating each row for a column that has data in it. Like Below:
I tried changing the Detail and Summary aggregations to Default, Total But those options are adding the entire columns value into single cells and not consistent.
Tried to Section and Group the Category field, but that just groups the Category name still repeating the no.of rows for each category.
Any idea on how to bring the output into single row for each category? I'm using Cognos 11.0.11 version.

That looks like a crosstab. Try simplifying the query item to this:
count( distinct [Sale Number] FOR [Metric], [Category] )
...and using a crosstab.
Or you could break out that part of the logic into a separate query with [Category], [Metric], and count(distinct [Sale Number]), then join it to the rest of your data. That would enable you to either use it in a crosstab, or to create a simpler expression for you "metric #" columns.

I think I just got lucky and figured out a solution. Updated the query to use running-count instead of count:
IF( 'Metric 1' IN ?pCompany?)
THEN
(
CASE
WHEN ( [Metric] = 'Metric 1' ) THEN
( running-count( distinct [Sale Number] FOR [Metric], [Category] ))
END
)
ELSE
( 0 )
And changed the Detail Aggregation to Count Distinct while Summary Aggregation set to None.
Got the output in a single row for each category. It doesn't work when I tried with only Count Distinct or running-count. It has to be a combination of both.

Related

Comma delimiter filter in Power BI

So I have a column like this in Power BI matrix
Country
India
India, Pakistan
Myanmar, Bhutan, India
I want to add a filter, where if I choose India, all the above three entries should return.
Currently my filter looks like this:
India
India, Pakistan
Myanmar, Bhutan, India
I want it to look like this
India
Pakistan
Myanmar
Bhutan
You can create a "NEW TABLE" from the modelling menu and use the following DAX query;
FilterTable =
VAR tmp =
ADDCOLUMNS ( Sheet1, "ItemPaths", SUBSTITUTE ( CONCATENATEX(Sheet1, Sheet1[Column1]), ",", "|" ) )
RETURN
DISTINCT(SELECTCOLUMNS (
GENERATE (
tmp,
ADDCOLUMNS (
GENERATESERIES ( 1, PATHLENGTH ( [ItemPaths] ) ),
"Items", TRIM(PATHITEM ( [ItemPaths],[Value], TEXT ))
)
),
"Countries", [Items]
))
Replace Sheet1 and Column1 with your table and column name...
Here are the steps which i followed to solve the issue
created a duplicate table as my source table
Deleted all the columns except the one which i wanted to keep a filter for
Duplicated that column and separated it row wise by removing the delimiter
Made a relation b/w my primary table and this newly created filter table
(the reln was showing as many to many but go ahead with it)
Apply in the filters, and the same solves the above issue.

Count unique matching items as a calculated column

I have two tables are Data and Report.
Data Table:
In Data table contain two columns are Item and status.
The item column contains duplicated entry and the item column contains text and number or number only or text only.
The status column contains two different text/comments, "Okay" and "Not Okay"
The report table
In the Report table, I updated both comments/text as "Okay" or "Not Okay".
I would like to create a new calculated column in the report table in order to get the unique count according to the comments based on the data table columns item and status.
In Excel, I am applying the following formula
F2=SUM((FREQUENCY(MATCH(A$2:$A$19&"",$A$1:$A$19&"",0)*($B$2:$B$19=$D3),ROW($A$2:$A$19))>0)+0)-1
in order to get my final result.
I don't want measure solutions.
DATA TABLE:
REPORT TABLE:
EXCEL LOGIC:
This is much easier in DAX than in Excel and there are many ways to do it.
Here are some possibilities with different approaches:
Desired Result =
VAR Comment = REPORT[COMMENTS]
RETURN
CALCULATE (
DISTINCTCOUNT ( DATA[ITEM] ),
DATA[STATUS] = Comment
)
Desired Result =
COUNTROWS (
SUMMARIZE (
FILTER ( DATA, DATA[STATUS] = REPORT[COMMENTS] ),
DATA[ITEM]
)
)
Desired Result =
SUMX (
DISTINCT ( DATA[ITEM] ),
IF ( CALCULATE ( SELECTEDVALUE ( DATA[STATUS] ) ) = REPORT[COMMENTS], 1, 0 )
)

Filter existing table to another table without adding measures or column on existing table

I want to create a table based on input table.
Input table is:
The new table filters the input table to show the last entry of every day.
I have tried working with measure but sometimes cant tell if it is working right until I graph it in pivot tables which is not so bad but sometimes just doesn't show me what I need to see exactly.
I have tried this measure:
History_Daily Efficiency =
VAR LastDailyEfficiency =
GENERATE(
VALUES ('Table_Full'[Cell]),
CALCULATETABLE (
TOPN (
1,
GROUPBY (
'Table_Full',
'Table_Full'[Date],
'Table_Full'[Time],
'Table_Full'[Efficiency]
),
'Table_Full'[Date], DESC,
'Table_Full'[Time], DESC,
'Table_Full'[Efficiency], ASC
)
)
)
RETURN
CALCULATE (
AVERAGE('Table_Full'[Efficiency]),
TREATAS( LastDailyEfficiency, 'Table_Full'[Cell], 'Table_Full'[Date], 'Table_Full'[Time], 'Table_Full'[Efficiency]),
'Table_Full'[Efficiency] < 80
)
But I got this:
I would like to see this as the output:
You can create a new table:
LastDayCount = GROUPBY(Table_Full;Table_Full[lob/Part Number];Table_Full[Date];"LastDate";MAXX(CURRENTGROUP(); Table_Full[DateTime]))
This will create a table with the last DateTime of the day.
Next we add a column giving us the max of that particular last datetime of the day. I noticed that you have more the same entries, the logic below takes the max part count at the end of the day when more than one entry.
Count =
CALCULATE(MAX(Table_Full[Part Count]);
FILTER(Table_Full;LastDayCount[Table_Full_lob/Part Number] = Table_Full[lob/Part Number]
&& LastDayCount[LastDate] = Table_Full[DateTime]))
End result:

How to Show last period (Fiscal Year) of sale, based on multi-filters report

I tried create a dashboard based on fiscal year, with more Filters, like region, sales rep name, ...
Example files avaliable on dropbox:
https://www.dropbox.com/sh/l25kdz6enmg35yb/AABPuOk3kKOpfQdKDfRUcnX2a?dl=0
On my closest attempt, i tried this follow:
Add one column on my data set, naming each period as distinct number, like: "17";"18";"19", due to deslocated fiscal year (april to march).
Then create a measure:
PREVIOUS CROP_YEAR = SWITCH(TRUE();
SELECTEDVALUE('dataset'[Crop-X])=16;(CALCULATE(SUM('dataset'[Order Value]);ALL('dataset')));
SELECTEDVALUE('dataset'[Crop-X])=17;(CALCULATE(SUM('dataset'[Order Value]);ALL('dataset')));
SELECTEDVALUE('dataset'[Crop-X])=18;(CALCULATE(SUM('dataset'[Order Value]);ALL('dataset')));
SELECTEDVALUE('dataset'[Crop-X])=19;(CALCULATE(SUM('dataset'[Order Value]);ALL('dataset')));
0)
Expected output was:
Values based on all filters applied, But instead i just get an empty charts
The measure is return the total because you are explicitly asking for it by using the ALL function. This removes all the filters from the dataset thus returning a grand total. This can work but it creates a complexity in your dataset with respect of having two time dimensions. The way to solve this is to first make sure you filter the date correctly with respect to both dimensions
PREVIOUS YEAR =
CALCULATE(
SUM('dataset'[Order Value]);
FILTER(
ALL ( 'dataset' ) ;
AND (
'dataset'[Crop-X] = MAX('dataset'[Crop-X]) -1 ;
'dataset'[YEAR] = MAX('dataset'[YEAR] ) -1
)
)
)
Furthermore, this measure still uses the ALL function which means any other filters get ignored. Using ALLSELECTED instead would result in the relative time filtering to result in nothing as soon as you select any time based slicer in your dashboard, this prevents the filter from looking at any other part of the dataset that is not within the primary sliced dataset. The workaround would be to use ALLEXCEPT and add the filters you want to be able to use as arguments. Downside is that any filter you add to your dashboard will have to be added to the exception manually.
PREVIOUS YEAR =
CALCULATE(
SUM('dataset'[Order Value]);
FILTER(
ALLEXCEPT( 'dataset' ; Dim1[Group] ; Dim1[Manager] ; Dim1[Region] ) ;
AND (
'dataset'[Crop-X] = MAX('dataset'[Crop-X]) -1 ;
'dataset'[YEAR] = MAX('dataset'[YEAR] ) -1
)
)
)

DAX - Histogram for relative frequencies and total column

I built a diagram that displays the relative frequencies of my clusters (on the values in the column) and the cumulated frequencies (on the values on the line).
My chart has this aspect:
I would like to add a new column to the right that is equal to the sum of all the values of the previous columns.
The relative frequencies are created using the code below:
"Frequencies UL" :=
CALCULATE (
DISTINCTCOUNT ( 'table1'[Column1] );
USERELATIONSHIP ( 'Order Cluster'[Cluster Name]; table1[tag Cluster] );
SUMMARIZE ( table1; table1[tag Cluster] )
)
I would really appreciate some help!
Thanks
Simply it was necessary to do this:
"Frequencies UL" := IF(SELECTEDVALUE('Order Cluster'[Is Total]);
CALCULATE(DISTINCTCOUNT ('table1'[Column1]); ALL('Order Cluster')); DISTINCTCOUNT('table1'[Column1]))
And this is the result I got!
I'd suggest creating a new table to use for your x-axis.
If your 'Order Cluster' table looks like this:
ClusterName Order
ClusterA 1
ClusterB 2
... ...
ClusterZ 26
You want to add a Total row to the end so try something along these lines:
NewTable = UNION('Order Cluster', {("Total", MAX('Order Cluster'[Order]) + 1)})
Use NewTable[ClusterName] for your chart's x-axis and tweak your cumulative measure to reference NewTable[Order] in the FILTER inequality.
You'll also need to adjust your frequency measure to handle the case when you have the Total cluster (use an IF or SWITCH) and make sure you're evaluating within the correct filter context. Something like this logic:
IF( MAX( NewTable[ClusterName] ) = "Total",
CALCULATE( [Frequency Calc], ALLSELECTED( table1 ) ),
CALCULATE( [Frequency Calc],
FILTER(
ALLSELECTED( table1 ),
table1[tag Cluster] = MAX( NewTable[Order] )
)
)
)
P.S. You might be better off adding the total row to your 'Order Cluster' table in the query editor instead of having another table floating around. In any case, the logic is similar; add a total row to the column you're using for your axis and adjust your measures to handle that category how you want.
A waterfall chart might be another option to consider (and doesn't need nearly as much work), though I don't know that you can include the percent info except in the tooltip.