NOT IN Dax equivalent - powerbi

still very new to DAX and hate it so far. where is the logic?
I have an expression below that creates data for a column based on if the data meets the criteria. What I have is a WORKING example of the opposite of what I'm trying to accomplish. I really, really want to be able to type "NOT IN" but it seems like that is not an option in DAX syntax. So basically, how do I EXCLUDE these values?
Column =
IF ( MMP_Dashboards_WMH_PBI[Revenue_Center] IN {"FillRate","CancelRt","NoShowRt","ExamRt"}, MMP_Dashboards_WMH_PBI[NewUnits] )
Would love for THIS to work:
Column =
IF ( MMP_Dashboards_WMH_PBI[Revenue_Center] NOT IN {"FillRate","CancelRt","NoShowRt","ExamRt"}, MMP_Dashboards_WMH_PBI[NewUnits] )

Try this:
IF ( NOT ( MMP_Dashboards_WMH_PBI[Revenue_Center] IN {"FillRate","CancelRt","NoShowRt","ExamRt"} ), MMP_Dashboards_WMH_PBI[NewUnits] )

Related

How do you exclude negative values in an iterator function?

I am putting together a measure of the difference between two datetime values and have ran into negative durations due to bad data, that I need to omit from the calculation.
My DAX function is as follows:
Job_length =
SUMX (
jobs ,
DATEDIFF (
jobs[actualstart] ,
jobs[actualend] ,
MINUTE
)
)
This returns the following output:
How can I change the formula to skip rows where the iterator expression returns a negative value?
The question is a bit lacklustre in the sense that it is perhaps the wrong question that is being asked! E.g. why is there data where actualstart < actualend to begin with? This is something you should fix in ETL prior to loading data into Power BI.
Or better yet, ensure that this is not allowed within your source systems. Perhaps there is a bad setting somewhere in your stack that results in this behavior in the data.
However, to do exactly as you describe you can apply a filter to the table you are iterating over within the SUMX function to remove rows that don't comply with the requirement. I have here assumed that only rows where actualend is strictly greater than actualstart are evaluated:
Job_length =
SUMX(
FILTER (
jobs ,
[actualstart] < [actualend]
),
DATEDIFF (
jobs[actualstart],
jobs[actualend],
MINUTE
)
)

Returning the first result of an table

I'm struggling within DAX to find a formula to return the first result. My table is as folllows:
The unique column is Dim_B_ID. So what I really would like to have is to return the first result of Amount ONLY for Dim_B_ID where the column IN is not blank. Im struggling cause I get answers like 3500 (total of the rows) and I can't seem to integrate IF(NOT(ISBLANK( funtion into this. So if someone has a solution for me, I would really appreciate it as I'm not so much of an expert in DAX.
You could try using the following measure:
FirstNonBlank =
FIRSTNONBLANKVALUE(
'Table'[Dim_Date_ID],
SUM( 'Table'[IN] )
)
When put together with Dim_B_ID in a table for example you could visualize FirstNonBlank for every "categorie" like so:
Used slightly modified sample data here:

Why using ALLSELECTED() AND FILTER() together?

I am trying to understand the below DAX code:
CALCULATE(
SUM(Revenue[Net])
,FILTER('Center', NOT 'Center'[Acc] IN {"RSM", BLANK() })
,ALLSELECTED()
,VALUES('Customer'[Customer Number])
)
I have the below questions:
What's the use of ALLSELECTED?? By definition ALLSELECTED returns all rows in a table, ignoring any filters that might have been applied inside the query, but keeping filters that come from outside. https://dax.guide/allselected/
So, what's the point of writing FILTER() if its going to be forced to be ignored by the next line (ALLSELECTED)?!?
Also by definition:
CALCULATE is just a expresion followed by filters...
What's the use of VALUES() ? It doesn't appear to be a filter, so how is it even allowed to appear there? (Per definition VALUES(): returns a one-column table that contains the distinct values from the specified column.)
I do not understand what is this returning? is it the SUM() or the VALUES()?
(I come from a SQL background, so any sql-friendly answer is appreciated).
In Dax every filter is a table of values its look similar to INNER JOIN;
ALLSELECTED is useful when you need to keep a row context (this is also a filter in DAX). You can use ALLSELECTED inside FILTER function.
For better understand what engine does you can use a DaxStudio with ServerTiming;
As you see this product one simple statement:
SELECT
SUM ( 'Table'[Cost Centre] )
FROM 'Table'
WHERE
'Table'[Project] NIN ( 'AB' ) ;
You can find useful article by Alberto Ferrari and Marco Russo:
https://www.sqlbi.com/tv/auto-exist-on-clusters-or-numbers-unplugged-22/
If it is only converting DAX queries if your connecting your sql analysis services to in DAX studio. because it is not working for PBI file data

Union table to itself with propagated filter

I'm new to Power BI and DAX, so bear with me.
I needed to union a table to itself when it is filtered. I need the filter from DimCompanySupplier[VAT] to propagate to InterestCategory[VAT] and union the result set from both filtered tables, all from the first input filter.
I am struggling to find the solution, I would really appreciate it if you could help me.
OpportunitiesByVAT =
VAR SelectedVat = SELECTEDVALUE ( DimCompanySupplier[VAT]; "ALL" )
RETURN
UNION (
CALCULATETABLE ( FactActiveOpportunities; DimCompanySupplier[VAT] = SelectedVat );
CALCULATETABLE ( FactActiveOpportunities; InterestCategory[VAT] = SelectedVat )
)
Thanks in advance!
Addressing your underlying problem to this question, your difficulty appears to be that you want a slicer that works using OR logic rather than AND logic.
Fortunately, this has been answered before. Please refer to this post:
Power BI Dashboard where the core filter condition is a disjunction on numeric fields

PowerBI - Use Value in Table View as Filter Parameter

This doesn't seem like it should be too complicated, but I'm not quite sure how to get it working.
I have a table in PowerBI with the following columns:
The columns in the database have an entry for Submitter and QAer
The QAs Posted column is basically just a COUNT of the Submitter
For QAs Pulled, I need to get the count of rows where the particular Submitter (in the first column) is listed as the QAer.
Is this something I can do?
Any help is appreciated, thanks!
EDIT: More about the data model - here's a screenshot example.
I think you are looking for something like this:
Measure =
COUNTROWS (
FILTER (
ALL( 'datatabel' ),
'datatabel'[QAer] = SELECTEDVALUE ( 'datatabel'[Submitter] )
)
)