cognos-using If statement -Issue with measure - if-statement

I am creating a report in Cognos Report Studio 10, using an if-statement
for displaying a Column chart. On the X-Axis I am using an if-statement as follows:
if (?Category?='Valve Material')
then ([Relational Model].[Catalog Elements].[Valve Material])
else
(if (?Category?='Valve Trim Characteristic')
then ([Relational Model].[Catalog Elements].[Valve Trim Characteristic])
else
([Relational Model].[Catalog Elements].[Valve Rating]))
and year in the series
and in measure I have given Sales Quantity.
This resulted in the following warning:
RQP-DEF-0578 A grand total will be returned for measure 'Component Sales Qty' in expression 'total([Presentation Layer].[Measure].[Component Sales Qty]
It's displaying the total value of sales quantity for all the inputs.
What changes should be done on the measure to get the individual sales quantity?

Related

PowerBI - Calculate average year from a date column

I have a table (we'll just call it MyTable) in PowerBI that includes a Date column. I have created a DateDimension table using CALENDARAUTO() with columns for the Date, Month#, MonthName, etc and created the relationship between that Date and the Date in MyTable.
I want to calculate the average year based on the records in MyTable. For example, if I have records with 1/1/2005, 1/1/2014, and 1/1/2015, the average year should be 2011.
How would I go about doing that? I've tried doing a measure of AVERAGE(DateDimension[Year]) and adding that to a Card visual, but it just shows 2.01K. If I do FORMAT(AVERAGE(DateDimension[Year]), "####"), the average is completely wrong.
Since you already have this DateDimension table, use
Average =
AVERAGEX(
MyTable,
RELATED(DateDimension[Year])
)
You can control the formatting by clicking on the measure (Average) and then using the Measure tools pane:
Set it to Whole number and no thousands operator.

Creating a DAX formula that will count columns with Filters/Restrictions removed

I have the formula to count monthly rows in Excel if the margin amount is negative. If the latest month has a positive margin then the formula returns a "False" if the latest month has a negative margin, then it counts how many columns (months) have been negative in the past.
=IF($AP5<0,(COUNTIF(D5:AP5,"<0")))
What I'm trying to write is an equivalent DAX formula that will do the same thing.
My DAX Formula is:
Months Negative= CALCULATE(
DISTINCTCOUNT('Listing'[Report Date].[Month]), FILTER('Listing', 'Listing'[Margin] <0))
Example of the data:
enter image description here
When I have the report filtered by November, each customer only reflects that it had only been negative for 1 month (November). Instead of showing that a customer has been negative for like 3 or 10 months as of November. The formula doesn't count any of the months prior that are negative.
Does anyone know how to change the dax formula so that it still would reflect the total count each negative column regardless of if the data is filtered by November?

PowerBI Measure - Previous Quarter With Filter

I am trying to create a measure to calculate the sum of sales for the previous quarter with a filter.
This is what I tried:
PQ Retail Sales = CALCULATE(SUM(MASTER_SALES_REPORTING_COMPETITION[Retail Sales $]),
FILTER(MASTER_SALES_REPORTING_COMPETITION,
MASTER_SALES_REPORTING_COMPETITION[Vendor Grouped] = "Company A"),
PREVIOUSQUARTER(DateDim[Date]))
Is there a logical error with the dax? PowerBI doesn't pick up any errors however I get a blank result.
Thank you.

Running total not aggregating on line chart

A table with some sales data has an associated running total measure. When viewed in Data view of PowerBi Desktop the data does reflect an aggregated total.
However when applied to a line chart the running total is simply the monthly totals. The expectation would be that a running total never decreases (assuming only positive sales) and that the line chart would reflect the values in the measure. So month by month should actually be 500, 1500, 3000.
Update 1: As per Foxans suggestion - same result:
Update 2: Works when using an index instead of a date (dd/MM/yyyy):
You ISONORAFTER filter should be based on Date instead of Spend for a running total (Or in the absence of a date column, should be the column which can identify the order you're trying to summarize, e.g. an incremental index), i.e.
Spend running total in Date =
CALCULATE(
SUM(Spend[Spend]),
FILTER(
ALLSELECTED(Spend),
ISONORAFTER(Spend[Date], MAX(Spend[Date]), DESC)
)
)
It's causing some confusion here because your sample data in Spend column is coincidentally in ascending order of values (100 -> 200 -> 300). If you update it to some random data, you'll notice it won't work in the first place.

DAX CALCULATE() doesn't seem to be overriding pivot filter

I am learning to use Power Pivot and write DAX and I am working through a book I bought written by Rob Collie and Avichal Singh called "Power Pivot and Power BI".
Early on it explains what happens when using CALCULATE() in a measure. A key point of understanding is explained as follows:
If a filter argument acts on a column that IS already on the pivot, it
will override the pivot context for that column
So in a simple table called "GSR" I have a series of invoices with an invoice date, a product and an amount. I have another column that converts all invoice dates to the last day of the month to gather them together. I have created a measure called "Total orders" that is counting the number of rows.
I have created a pivot of this data with:
Products in the rows
Month end in the columns (but I've actually chosen Month and Year from the automatic breakdown Power Pivot has done on my Month_End column)
Orders in the values
This pivot renders correctly.
Now the issue:
I've created two slicers that are feeding off two disconnected tables; one containing month numbers, and one containing years. Based on the selection from each of these I have a measure that creates a month end using the EOMONTH(DATE(),0). This measure is called "Comparison_Month_End".
I then have another measure called "Compare_Orders" that contains the following:
CALCULATE([Total orders],FILTER(GSR,GSR[Month_End]=[Comparison_Month_End]))
The point of all of this - this is meant to get the orders from the GSR where the month and year match the slicer selection. I want this value to appear in the pivot for every month selected i.e. not filtered by the pivot.
It doesn't work, however. This seems to me to be counter to what the book says, which is that if the filter in the measure is applied to a column on the pivot (in this case Month_End), the pivot filter is overriden. So, for example, if I have 31-Mar-18 in a column on my pivot and the comparison month end is 31-Jan-18, I would expect to see the January orders within "Compare_Orders" sitting next to the March orders, the February orders, the December orders and so on, but it only appears next to January.
To me this is doing exactly the same as an example in the book where there is a pivot with Year in the rows, Total Sales in column 1 and then 2002 sales in column 2. Column 1 shows sales for each year, column 2 shows the same sales figure (i.e. 2002 sales) against every row, even where the row year is 2001, 2003 or 2004. The 2002 Sales measure is using CALCULATE() summing Total Sales, filtering on "Sales[Year] = 2002".
Could anyone please explain why what I expected to happen doesn't seem to be happening please?
Thank you.
CALCULATE does indeed override the filter context when evaluating its first argument; using the rows provided to its second argument as the new filter context. However; CALCULATE does not alter the filter context when evaluating its second argument, and so pre-existing filters remain unless they are explicitly removed.
In FILTER(GSR,GSR[Month_End]=[Comparison_Month_End]), FILTER only iterates over rows of GSR that are present in the pre-existing filter context (the pivot context). To get all rows, use ALL:
CALCULATE([Total orders],FILTER(ALL(GSR),GSR[Month_End]=[Comparison_Month_End]))