I have imported a dataflow from a database into PowerBI. I am trying to write a DAX statement to mimic these constraints on a query I made:
SELECT COUNT(IPID) as theSwitches
FROM MVIEW_E_SWITCH
WHERE (NORMALPOSITIONA = 0 OR NORMALPOSITIONB = 0 OR NORMALPOSITIONC = 0)
AND (FEEDERID2 IS NULL)
Here is my DAX statement:
Open =
( MVIEW_E_SWITCH[NORMALPOSITIONA] = 0
|| MVIEW_E_SWITCH[NORMALPOSITIONB] = 0
|| MVIEW_E_SWITCH[NORMALPOSITIONC] = 0 )
& ( ISBLANK ( MVIEW_E_SWITCH[FEEDERID2] ) )
Dummy Data is below.
IPID NORMALPOSITIONA NORMALPOSITIONB NORMALPOSITIONC FEEDERID2
123141 1 1 1 GC12
145361 0 0 1
096842 0 0 0 BC32
053912 0 0 0
018249 1 1 1
827247 0 1 0 HD32
In DAX, & denotes string concatenation. Use && for logical AND.
Edit: Given that FEEDERID2 is text, I'm guessing your problem is that you have empty strings "" instead of true blanks. Instead of ISBLANK ( MVIEW_E_SWITCH[FEEDERID2] ) try
( ISBLANK ( MVIEW_E_SWITCH[FEEDERID2] ) || MVIEW_E_SWITCH[FEEDERID2] = "" )
or
LEN ( MVIEW_E_SWITCH[FEEDERID2] ) = 0
Try this solution if it helps mark it as the answer.
Create a calculated column with the following DAX:-
Open = IF((Table[NPA] = 0 || Table[NPB] = 0 || Table[NPC] = 0) && ISBLANK(Table[FEEDERID]), TRUE(), FALSE())
This should give you the desired output.
P.S. Column is to check if the FEEDERID is blank or not.
Related
please can you let me know why these two measures produce different results? I am obv missing something simple to do with AND and OR. thank you.
measure 1 = CALCULATE (
COUNT ( fct_core[colour] ),
fct_core[type] = 1
|| fct_core[type] = 2
|| fct_core[type] = 3
&& fct_core[colour] = 5
|| fct_core[colour] = 6
|| fct_core[colour] = 7
|| fct_core[colour] = 8
)
measure 2 = CALCULATE (
COUNT ( fct_core[colour] ),
fct_core[type] >= 1
&& fct_core[type] <= 3
&& fct_core[colour] = 5
|| fct_core[colour] = 6
|| fct_core[colour] = 7
|| fct_core[colour] = 8
)
This is an order of operations misunderstanding.
If you put in appropriate parentheses, then these measures should be the same (assuming types only have integer values).
measure 1 =
CALCULATE (
COUNT ( fct_core[colour] ),
(
fct_core[type] = 1 ||
fct_core[type] = 2 ||
fct_core[type] = 3
)
&&
(
fct_core[colour] = 5 ||
fct_core[colour] = 6 ||
fct_core[colour] = 7 ||
fct_core[colour] = 8
)
)
measure 2 =
CALCULATE (
COUNT ( fct_core[colour] ),
(
fct_core[type] >= 1 &&
fct_core[type] <= 3
)
&&
(
fct_core[colour] = 5 ||
fct_core[colour] = 6 ||
fct_core[colour] = 7 ||
fct_core[colour] = 8
)
)
I have created a dashboard in PBI using a dataflow from a live database. I am trying to replicate the constraints of a query in DAX and am a little lost on how to get the correct DAX syntax/results.
Below is the query:
SELECT count(IPID) as theSwitches
FROM KUB.MVIEW_E_SWITCH
WHERE (NORMALPOSITIONA = 0 OR NORMALPOSITIONB = 0 OR NORMALPOSITIONC = 0)
AND (FEEDERID <> FEEDERID2)
AND FEEDERID2 is not null
Here is my DAX:
TIE= (MVIEW_E_SWITCH[NORMALPOSITIONA]= 0 ||
MVIEW_E_SWITCH[NORMALPOSITIONB] = 0 ||
MVIEW_E_SWITCH[NORMALPOSITIONC]= 0)
&& (MVIEW_E_SWITCH[FEEDERID] <> MVIEW_E_SWITCH[FEEDERID2])
&& NOT(ISBLANK(MVIEW_E_SWITCH[FEEDERID2]))
Here is some dummy data:
IPID NORMALPOSITIONA NORMALPOSITIONB NORMALPOSITIONC FEEDERID FEEDERID2
123141 1 1 1 GC21 GC12
145361 0 0 1
096842 0 0 0 BC21 BC32
053912 0 0 0
018249 1 1 1
827247 0 1 0 HD32 HD32
I know it is not going to count these, but I wanted to just get a true/false column and only count the true values for my report section of the PBIX.
Is Dax the correct language to perform this, or should I look to use M Code in the Power Query Editor? Any thoughts would be greatly appreciated.
Thanks!
Here is measure:
TIE = COUNTROWS (CALCULATETABLE(Sheet2, Sheet2[NORMALPOSITIONA]= 0 ||
Sheet2[NORMALPOSITIONB] = 0 ||
Sheet2[NORMALPOSITIONC]= 0
&& (Sheet2[FEEDERID] <> Sheet2[FEEDERID2])
&& NOT(ISBLANK(Sheet2[FEEDERID2]))))
Hi please try the following solution if it helps please mark it as the answer.
Create a calculated column with the following DAX:
Open FID2 =
IF (
AND(
(Table[NPA] = 0 || Table[NPB] = 0 || Table[NPC] = 0 )
&& NOT ( ISBLANK ( Table[FEEDERID2] ) ),
Table[FEEDERID] <> Table[FEEDERID2]
),
TRUE (),
FALSE ()
)
I am a new PowerBi user and I would like to create a primary/foreign key relationship using a DAX formula which will return the id of the corresponding line to me.
I have two tables:
CompanyXFlights
GlobalFlights
The dax formula:
Exist =
COALESCE (
CALCULATE (
COUNTROWS ( CompanyXFlights );
FILTER (
CompanyXFlights;
OR (
AND (
GlobalFlights[ArrivalDateTime]
< CompanyXFlights[DateTime] + TIME ( 0; 10; 0 );
GlobalFlights[ArrivalDateTime]
> CompanyXFlights[DateTime] - TIME ( 0; 10; 0 )
);
AND (
GlobalFlights[DepratureDateTime]
< CompanyXFlights[DateTime] + TIME ( 0; 10; 0 );
GlobalFlights[DepratureDateTime]
> CompanyXFlights[DateTime] - TIME ( 0; 10; 0 )
)
)
&& GlobalFlights[AircraftRegistrationCode]
= CompanyXFlights[AircraftRegistrationCode]
)
);
0
)
I'm using this formula to get the number of corresponding lines, but now I want it to return the index (id) of the line. What should I change? Should I put CompanyXFlights[Id] instead of COUNTROWS(CompanyXFlights) or should I use another formula?
I found the solution, and it was quite simple, i just changed COUNTROWS(CompanyXFlights) by SELECTEDVALUE(CompanyXFlights[Id]);
I have a requirement like this,
P.No. BR IND SC TD RM CD PD Out - Col - Required
1 B N T 2/1/2011 2/1/2011 5/1/2007 1/1/2007 1
1 B N T 2/1/2011 2/1/2011 5/1/2010 2/1/2011 1
1 B N T 2/1/2011 6/1/2019 5/1/2007 2/1/2011 0
1 B N T 2/1/2011 1/1/2019 5/1/2007 2/1/2011 0
THE Out-Col-Required is what I am trying to do using DAX - Calculated Column.
This is the Logic that it follows,
Filter the Table for the following first in DAX,
BR = B, IND = N, SC = T, TD = RM
Then identify the Min CD date and Max PD date for P.No.
if the diff is less than 30 months, then 1 else 0.
Kindly help me with this.
Thanks.
Out =
VAR PNo = OutCol[P.No.]
VAR filt =
FILTER (
OutCol;
OutCol[P.No.] = PNo
&& OutCol[TD] = OutCol[RM]
&& OutCol[BR] = "B"
&& OutCol[IND] = "N"
&& OutCol[SC] = "T"
)
VAR monthsDiff =
CALCULATE (
DATEDIFF (
MIN ( OutCol[CD] );
MAX ( OutCol[PD] );
MONTH
);
filt
)
RETURN
IF (
OutCol[TD] = OutCol[RM]
&& OutCol[BR] = "B"
&& OutCol[IND] = "N"
&& OutCol[SC] = "T"
&& monthsDiff < 30;
1;
0
)
I have simple table:
Column Desired result
Messi Ronaldo 0
Ronaldo 0
Messi Pogba 0
Messi alala 1
And I try to count how many times Messi is in the string and Ronaldo and Pogba are not present.
The code I have got is:
Desired result =
IF (ISBLANK ( SEARCH ( "Messi", 'Table'[Column], 1, BLANK () ) )
&&
(
ISBLANK ( SEARCH ( "Ronaldo", 'Table'[Column], 1, BLANK () ) )
||ISBLANK ( SEARCH ( "Pogba", 'Table'[Column], 1, BLANK () ) )
)
,
0,
1)
But it does not exclude Ronaldo or Pogba?
Current(wrong) results
Column Current results
Messi Ronaldo 1
Ronaldo 0
Messi Pogba 1
Messi alala 1
Try this instead:
Desired result =
IF (NOT(ISBLANK ( SEARCH ( "Messi", 'Table'[Column], 1, BLANK () ) ))
&& ISBLANK ( SEARCH ( "Ronaldo", 'Table'[Column], 1, BLANK () ) )
&& ISBLANK ( SEARCH ( "Pogba", 'Table'[Column], 1, BLANK () ) ),
1,
0)
This returns 1 if searching for "Messi" doesn't return a blank but the search for "Ronaldo" and "Pogba" do return a blank.