Using filter inside a calculated memeber - filter

I'm having some MDX issues, I want to calculate how many products I have per type per version, this would be my output.
ProductID | QtyProductAVersionA | QtyProductAVersionB | QtyProductBVersionA | QtyProductBVersionB |
I have this MDX so far
WITH MEMBER [Measures].[ProductAVersionA]
AS SUM([DimProduct].[ProductName].&[ProductA],[Measures].[ProductQty])
SELECT NON EMPTY (
[Measures].[ProductAVersionA]) ON COLUMNS,
NON EMPTY [DimOrg].[ProductID].[ProductID].MEMBERS ON ROWS
FROM [Sales]
WHERE([DimCustomers].[Customer Area].&[United States])
But this returns the total of product A, I want only the product A filtered by version A. I can't use it in the WHERE clause since not all my products have the same versions.
Is there any way I can achieve this with a Filter expression inside the calculated memeber? I tried to used but I kept getting an error.
FYI product version is in another dimension [DimVersion]
Any help would be appreciated

You could try filtering the ProductAVersionA calculated member by the DimVersion 'A' member as follows:
member [Measures].[ProductAVersionA] as
sum(([DimProduct].[ProductName].&[ProductA], [DimVersion].[VersionName].&[VersionA]), [Measures].[ProductQty])

Related

Wrong sorting while using Query function

I've been trying to do a report about the quantity of breakdonws of products in our company. The problem is that the QUERY function is operating as normal, but the sorting order is well - a bit strange.
The data I'm trying to sort are as follows (quantities are blacked out since I cannot share those informations):
Raw data
First column - name of the product, second, it's EAN code, third, breakdown rate for last year, last column - average breakdown rate. "b/d" means "brak danych" or no data.
What I want to achieve is to get the end table with values sorted by average breakdown rate.
My query is as follows:
=query(Robocze!A2:D;"select A where A is not null and NOT D contains 'b/d' order by D desc")
Final result
As You can see, we have descending order, but there are strange artifacts - like the 33.33% after 4,00% and before 3,92%.
Why is that!?
try:
=INDEX(LAMBDA(x; SORT(x; INDEX(x;; 4)*1; 0))
(QUERY(Robocze!A2:D; "where A is not null and NOT D contains 'b/d'"; 0));; 4)

How to Select multiple related columns in add calculated fields in Quicksight parameter using ifelse?

I have a parameter 'type' in a table and it can have multiple values as follows -
human
chimpanzee
orangutan
I have 3 columns related to each type in the table -
human_avg_height, human_avg_weight, human_avg_lifespan
chimpanzee_avg_height, chimpanzee_avg_weight, chimpanzee_avg_lifespan
orangutan_avg_height, orangutan_avg_weight, orangutan_avg_lifespan
So if i select the type as human, the quicksight dashboard should only display the three columns -
human_avg_height, human_avg_weight, human_avg_lifespan
and should not display the following columns -
chimpanzee_avg_height, chimpanzee_avg_weight, chimpanzee_avg_lifespan
orangutan_avg_height, orangutan_avg_weight, orangutan_avg_lifespan
I created the parameter type and in the add calculated fields I am trying to use ifelse to select the columns based on the parameter selected as follows -
ifelse(${type}='human',{human_avg_height}, {human_avg_weight}, {human_avg_lifespan},{function})
I also tried -
ifelse(${type}='human',{{human_avg_height}, {human_avg_weight}, {human_avg_lifespan},{function}})
And -
ifelse(${type}='human',{human_avg_height, human_avg_weight, human_avg_lifespan},{function}})
But none of it is working. What am i doing wrong ?
One way to do this would be to use three different calculated fields, one for all the heights, one for weights and one for lifespan. The heights one would look like this:
ifelse(
${type}='human',{human_avg_height}, ifelse(
${type}='chimpanzee', { chimpanzee_avg_height}, ifelse(
${type}='orangutan',{ orangutan_avg_height},
NULL
)))
Make another calculated field for weights and lifespan and then add these calculated fields to your table, and filter by type.
To make it clear to the viewer what data is present, edit the Title of the visual to include the type:
${type} Data
You have to create one calculated field for each measure using the ifelse with the type to choose the correct vale, but is not necessary to create inner ifelse as skabo did, the if else syntax is ifelse(if, then [, if, then ...], else) so you can define the calculated fields as follows:
avg_height = ifelse(${type}='human', {human_avg_height}, ${type}='chimpanzee', {chimpanzee_avg_height},${type}='orangutan', {orangutan_avg_height}, NULL)
avg_weight = ifelse(${type}='human', {human_avg_weight}, ${type}='chimpanzee', {chimpanzee_avg_weight},${type}='orangutan', {orangutan_avg_weight}, NULL)
avg_lifespan = ifelse(${type}='human', {human_avg_lifespan}, ${type}='chimpanzee', {chimpanzee_avg_lifespan},${type}='orangutan', {orangutan_avg_lifespan}, NULL)
Then use those calculated fields in your visuals.

Power BI DAX measure: Count occurences of a value in a column considering the filter context of the visual

I want to count the occurrences of values in a column. In my case the value I want to count is TRUE().
Lets say my table is called Table and has two columns:
boolean value
TRUE() A
FALSE() B
TRUE() A
TRUE() B
All solutions I found so far are like this:
count_true = COUNTROWS(FILTER(Table, Table[boolean] = TRUE()))
The problem is that I still want the visual (card), that displays the measure, to consider the filters (coming from the slicers) to reduce the table. So if I have a slicer that is set to value = A, the card with the count_true measure should show 2 and not 3.
As far as I understand the FILTER function always overwrites the visuals filter context.
To further explain my intent: At an earlier point the TRUE/FALSE column had the values 1/0 and I could achieve my goal by just using the SUM function that does not specify a filter context and just acts within the visuals filter context.
I think the DAX you gave should work as long as it's a measure, not a calculated column. (Calculated columns cannot read filter context from the report.)
When evaluating the measure,
count_true = COUNTROWS ( FILTER ( Table, Table[boolean] = TRUE() ) )
the first argument inside FILTER is not necessarily the full table but that table already filtered by the local filter context (including report/page/visual filters along with slicer selections and local context from e.g. rows/column a matrix visual).
So if you select Value = "A" via slicer, then the table in FILTER is already filtered to only include "A" values.
I do not know for sure if this will fix your problem but it is more efficient dax in my opinion:
count_true = CALCULATE(COUNTROWS(Table), Table[boolean])
If you still have the issue after changing your measure to use this format, you may have an underlying issue with the model. There is also the function KEEPFILTERS that may apply here but I think using KEEPFILTERS is overcomplicating your case.

RRSR Sorting i got "a sort expression for the tablix4 includes an aggregate function"

i add you my view of my report
a busy cat http://s3.subirimagenes.com:81/imagen/previo/thump_7631306captura.png
You can see that the group parent is NOM CLIENTE (ACCOUNT) after it has a
child group called fecha(date) after every fecha(date) has a few pro
code (product code), and every pro code has a cantidad(quantity), and
every (pro codigo * cantidad) (product code * quantity) has its
importe(amount) so, every fecha(date) has its importe (its total
quantity bought that day) now every client has a total quantity (all
his/her purchases) and now i want to sort my report but this last
total quantity, you could see
837,25000
549,60000
1004,0000
369,50000
464,50000
the order should be:
1004,0000
837,25000
549,60000
464,50000
369,50000
when i do a sorting on the upper left corner and i put this function on the sort tab
=Sum(Fields!importe.Value)
i get this message:
an error ocurred during local report processing. the definition of the
report /best_accounts is invalid A sort expression for the tablix
'Tablix4' includes an aggregate function. Aggregate functions cannot
be used in data row sort expressions.
then how can i sorted as i want?
go to the matrix proprieties
select the group's tab
select the group's row and edit it
you should see a sorting tab.
enter the total expression and select ASC or DESC
A sort expression for the tablix ‘Tablix3’ uses the function RowNumber. RowNumber cannot be used in sort expressions.

Propel: How the "Affected Rows" Returned from doUpdate is defined

In propel there is this doUpdate function, that will return the numbers of affected rows by this query.
The question is, if there is no need to update the row ( because the set value is already the same as the field value), will those rows counted as the affected row?
Take for example, I have the following table:
ID | Name | Books
1 | S1oon | Me
2 | S1oon | Me
Let's assume that I write a ORM function of the equivalent of the following query:
update `new table` set
Books='Me'
where Name='S1oon';
What will the doUpdate result return? Will it return 0 ( because all the Books column are already Me, hence there is no need to update), or will it be 2 ( because there are 2 rows that fulfill the where condition) ?
Under the hood, Propel is using PDO's PDOStatement::rowCount() method to return the number of affected rows. So, the short answer is that you'll get "2" as you expect here, but the longer answer is that it may depend slightly on how PDO implements that function for your specific database. (I think if you did not get 2, it should be a bug for PDO, however.)
See the description of rowCount() in the PHP manual for more info.
One other thing to bear in mind is that when Propel calls methods (like save() or delete()) which are expected to return number-of-rows-modified and which may result in more than one row being modified (e.g. if you add a Book and its Author and then cause both to be INSERTed by calling book->save()), you will get the total number of rows modified.
It will return 2.

Resources